예제 #1
0
        public ActionResult Create(LoanFormViewModel model)
        {
            if (AclHelper.hasAccess(User, currentAction, currentController))
            {
                if (ModelState.IsValid)
                {
                    model.LoanForm.RequestorId = AclHelper.GetUserId(User.Identity.Name);
                    model.LoanForm.RequestNo   = 0;
                    model.LoanForm.UpdatedDate = DateTime.Now;
                    model.LoanForm.CreatedDate = DateTime.Now;

                    db.rs_loan_form.Add(model.LoanForm);
                    db.SaveChanges();

                    foreach (string bookId in model.Bookings.BookingIds)
                    {
                        int id;
                        int.TryParse(bookId, out id);
                        rs_bookings booking = db.rs_bookings.Find(id);

                        if (booking != null)
                        {
                            booking.LoanFormId      = model.LoanForm.LoanId;
                            db.Entry(booking).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                    return(RedirectToAction("Index"));
                }

                return(View(model));
            }
            else
            {
                return(RedirectToAction("NotAuthenticated", "Home"));
            }
        }
예제 #2
0
 public BookModel()
 {
     Asset   = new rs_assets();
     booking = new rs_bookings();
 }