Beispiel #1
0
        public IHttpActionResult Put(UserBookJoinEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateUserBookJoinService();

            if (!service.UpdateUserBookJoin(model))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
        public bool UpdateUserBookJoin(UserBookJoinEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .UserBookJoins
                    .Single(e => e.Id == model.JoinId);
                entity.ReaderId    = ctx.Users.FirstOrDefault(x => x.UserName == model.UserName).Id;
                entity.BookId      = ctx.Books.FirstOrDefault(y => y.Name == model.BookName).Id;
                entity.UserName    = model.UserName;
                entity.BookName    = model.BookName;
                entity.Rating      = model.Rating;
                entity.Review      = model.Review;
                entity.ModifiedUtc = DateTimeOffset.Now;

                return(ctx.SaveChanges() == 1);
            }
        }