BillableHoursWebApp.Api.Controllers.ProjectsController.Put C# (CSharp) Méthode

Put() private méthode

private Put ( int id ) : IHttpActionResult
id int
Résultat IHttpActionResult
        public IHttpActionResult Put(int id)
        {
            var result = this.data.Projects
                .Find(x => x.Id == id).FirstOrDefault();

            if (result == null)
            {
                return this.BadRequest("No project with that id is present.");
            }

            var currentUserId = User.Identity.GetUserId();

            var user = this.data.Employees.Find(x => x.Id == currentUserId).FirstOrDefault();

            if (user == null)
            {
                return this.BadRequest("Only employees can work on projects!");
            }

            if (result.Employee != null)
            {
                return this.BadRequest("The project is already being worked on!");
            }

            result.Employee = user;
            result.Employee.Projects.Add(result);

            this.data.Projects.Update(result);
            this.data.SaveChanges();

            var message = string.Format("Project activity: User {0} began working on {1}'s project | {2}", user.Email, result.Client.Email, "/projects");

            pubnubClient.Broadcast(Constants.PubnubChannelActivityFeed, message, str => { }, s => { });

            return this.Ok(result.Id);
        }