Пример #1
0
        public ActionResult Create(BorrowCreateViewModel model)
        {
            if (model.ChoosenBooks.Contains(-1))
            {
                ModelState.AddModelError("emptyBook", "Each list must have a book selected");
            }
            if (model.ChoosenBooks.Length != model.ChoosenBooks.Distinct().Count())
            {
                ModelState.AddModelError("haveDuplicate", "It isn't possible to borrow two identical books.");
            }
            if (!ModelState.IsValid)
            {
                var errorList = (from item in ModelState
                                 where item.Value.Errors.Any()
                                 select item.Value.Errors[0].ErrorMessage).ToList();
                return(Json(new { success = false, errors = errorList }, JsonRequestBehavior.AllowGet));
            }

            borrowService.InsertBorrows(model);
            return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
        }