Пример #1
0
        public async Task <IActionResult> New(AddNewRentModel model)
        {
            if (ModelState.IsValid)
            {
                var rentStartDate = new DateTime(model.StartYear, model.StartMonth, model.StartDay);
                var rentEndDate   = rentStartDate.AddDays(model.RentDayCount);

                var cliemUserID = User.Claims.FirstOrDefault(a => a.Type.Equals("UserID"));
                var userID      = int.Parse(cliemUserID.Value.ToString());

                var rent = new RentHistory()
                {
                    BookID          = model.BookID,
                    CreatedDate     = DateTime.Now,
                    LastUpdatedDate = DateTime.Now,
                    isDelayed       = false,
                    MemberID        = model.MemberID,
                    RentDate        = rentStartDate,
                    RentEndDate     = rentEndDate,
                    DelayedDayCount = 0,
                    UserID          = userID,
                    DelayFine       = 0,
                };

                var result = await rentService.AddAsync(rent);

                if (result.isSuccess)
                {
                    return(RedirectToAction("Index"));
                }
                foreach (var item in result.Errors)
                {
                    ModelState.AddModelError("", item);
                }
            }
            return(View(model));
        }