public IHttpActionResult PatchBug(int id, BugInputModel bugData)
        {
            var bug = this.db.Bugs.Find(id);
            if (bug == null)
            {
                return this.NotFound();
            }

            if (bug.Title != bugData.Title && bugData.Title != null)
            {
                bug.Title = bugData.Title;
            }
            if (bug.Description != bugData.Description && bugData.Title != null)
            {
                bug.Description = bugData.Description;
            } if (bug.Status != bugData.Status && bugData.Title != null)
            {
                bug.Status = bugData.Status;
            }

            bug.SubmitedDate = DateTime.Now;

            
            this.db.SaveChanges();

            return this.Ok(new {Message = "Bug #"+bug.Id+" patched." });
        }
        public IHttpActionResult PostBug(BugInputModel bug)
        {
            if (bug == null)
            {
                return this.BadRequest("Missing Bug data.");
            }

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (this.db.Bugs.Any(b => b.Title == bug.Title))
            {
                return this.Content(HttpStatusCode.Conflict,
                    new { Message = "Duplicated Bug Title: " + bug.Title });
            }
            var currentId = this.User.Identity.GetUserId();
           // var author = this.db.Users.Where(u => u.Id == currentId).Select(u => u.Id).FirstOrDefault();
            var bugData = new Bug()
                {
                     Title = bug.Title,
                     Description = bug.Description != null ? bug.Description : null,
                     AuthorId = currentId,
                     Status = StatusTypes.Open,
                     SubmitedDate = DateTime.Now
                };


            db.Bugs.Add(bugData);
            db.SaveChanges();

            if (currentId == null)
            {
                return this.CreatedAtRoute("DefaultApi",
                new { controller = "BugsController", id = bugData.Id },
                new
                {
                    Id = bugData.Id,
                    Message = "Anonymous bug submitted."

                });
            }
            return this.CreatedAtRoute("DefaultApi",
                new { controller = "BugsController", id = bugData.Id },
                new
                {
                    Id = bugData.Id,
                    Author = User.Identity.GetUserName(),
                    Message = "User bug submitted."

                });
            
            
        }