示例#1
0
        public ActionResult Edit(ShiftModel model)
        {
            var shift = _shiftRepository.GetById(model.Id);

            if (ModelState.IsValid)
            {
                if (shift.DaysInPattern != model.DaysInPattern)
                {
                    //Reset the old Shift Patterns
                    ResetOldShiftPatterns(shift);
                    //create the new Shift Patterns Model
                    CreateNewShiftPatterns(model);
                }
                shift = model.ToEntity(shift);
                //always set IsNew to false when saving
                shift.IsNew = false;
                _shiftRepository.Update(shift);

                //commit all changes
                this._dbContext.SaveChanges();

                //notification
                SuccessNotification(_localizationService.GetResource("Record.Saved"));
                return(new NullJsonResult());
            }
            else
            {
                return(Json(new { Errors = ModelState.SerializeErrors() }));
            }
        }
示例#2
0
        public virtual IActionResult Edit(ShiftModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageDoctors))
            {
                return(AccessDeniedView());
            }

            //get a specified id shift
            var shift = _shiftService.GetShiftById(model.Id);

            if (shift == null)
            {
                return(RedirectToAction("List"));
            }


            try
            {
                if (ModelState.IsValid)
                {
                    shift = model.ToEntity(shift);
                    shift.UpdatedOnUtc = DateTime.UtcNow;
                    shift.UpdatedBy    = _workContext.CurrentCustomer.Id;
                    _shiftService.UpdateShift(shift);
                    //activity log
                    _customerActivityService.InsertActivity("EditShift",
                                                            string.Format(_localizationService.GetResource("ActivityLog.EditShift"), shift.Name), shift);

                    SuccessNotification(_localizationService.GetResource("Hero.Admin.Shifts.Updated"));

                    return(continueEditing ? RedirectToAction("Edit", new { id = shift.Id }) : RedirectToAction("List"));
                }

                //prepare model
                model = _shiftModelFactory.PrepareShiftModel(model, shift, true);

                return(View(model));
            }
            catch (Exception exc)
            {
                ErrorNotification(exc);

                return(RedirectToAction("Edit", new { id = shift.Id }));
            }
        }
示例#3
0
        public virtual IActionResult Create(ShiftModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageShifts))
            {
                return(AccessDeniedView());
            }

            if (!string.IsNullOrWhiteSpace(model.Code) && _shiftService.GetShift(w => w.Code == model.Code) != null)
            {
                ModelState.AddModelError(string.Empty, _localizationService.GetResource("Hero.Admin.Shifts.CodeIsRegister"));
            }


            if (ModelState.IsValid)
            {
                var shift = model.ToEntity <Shift>();
                shift.CreatedOnUtc = DateTime.UtcNow;
                shift.CreatedBy    = _workContext.CurrentCustomer.Id;
                shift.UpdatedBy    = null;
                shift.UpdatedOnUtc = null;
                _shiftService.InsertShift(shift);

                //activity log
                _customerActivityService.InsertActivity("AddNewShift",
                                                        string.Format(_localizationService.GetResource("ActivityLog.AddNewShift"), shift.Id), shift);

                SuccessNotification(_localizationService.GetResource("Hero.Admin.Shifts.Added"));

                if (!continueEditing)
                {
                    return(RedirectToAction("List"));
                }

                //selected tab
                SaveSelectedTabName();

                return(RedirectToAction("Edit", new { id = shift.Id }));
            }

            //prepare model
            model = _shiftModelFactory.PrepareShiftModel(model, null, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }