Beispiel #1
0
        public ActionResult LMS_Create([DataSourceRequest] DataSourceRequest request, vm_Grid viewModel)
        {
            var db = new LeaveManagementSystemContext();
            ActiveDirectoryWarehouseContext dbAD = new ActiveDirectoryWarehouseContext();

            var staffLoginID = User.Identity.Name.Split('\\')[1];

            var staffProfile = dbAD.UserProfiles
                               .Where(w => w.PKUserName.Equals(staffLoginID))
                               .FirstOrDefault();

            dbAD.Dispose();

            if (viewModel != null && ModelState.IsValid)
            {
                var model = new UserManagement();

                model.PK_ID                  = viewModel.PK_ID;
                model.AuthName               = staffProfile.PKUserName;
                model.StartDate              = viewModel.StartDate;
                model.EndDate                = viewModel.EndDate;
                model.Reason                 = viewModel.Reason;
                model.IsApproved             = viewModel.IsApproved;
                model.Entitlement            = viewModel.Entitlement;
                model.BreakDuration          = viewModel.BreakDuration;
                model.RemainingDays          = viewModel.RemainingDays;
                model.IsEntitlementOvertaken = viewModel.IsEntitlementOvertaken;

                db.Add(model);
                db.SaveChanges();
                viewModel.PK_ID = model.PK_ID;
                SendMail(viewModel);
                db.Dispose();
            }
            return(Json(new[] { viewModel }.ToDataSourceResult(request, ModelState)));
        }