Пример #1
0
        public ActionResult MarkRead(Reading reading)
        {
            if(ModelState.IsValid)
            {
                var book = _bookRepo.Find(reading.BookId);
                reading.Book = book;
                _badgeRepo.CreateBadgesForBookRead(reading);
                reading.State = State.Added;
                _repo.InsertOrUpdateGraph(reading);
                _unitOfWork.Save();
                return Json(new {Success=true}, JsonRequestBehavior.AllowGet);
            }

            var errors = ModelState
                .Where(_ => _.Value.Errors.Any())
                .Select(_=>new {Field=_.Key, Error=_.Value.Errors.First().ErrorMessage})
                .ToList();
            
            //this.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
            return Json(new { Success=false,Errors = errors }, JsonRequestBehavior.AllowGet);
        }
Пример #2
0
 public BookVM(Reading reading): this(reading.Book)
 {
     LastRead = reading.Date;
 }