コード例 #1
0
        public virtual IActionResult Edit(DepartmentModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers))
            {
                return(AccessDeniedView());
            }
            //try to get a customer role with the specified id
            var department = _departmentService.GetById(model.Id);

            if (department == null)
            {
                return(RedirectToAction("List"));
            }
            try
            {
                if (ModelState.IsValid)
                {
                    department = model.ToEntity(department);
                    department.UpdatedOnUtc = DateTime.UtcNow;
                    department.UpdatedBy    = _workContext.CurrentCustomer.Id;
                    department.HospitalId   = _workContext.HospitalId;

                    if (department.Path != "0")
                    {
                        var listPath = department.Path.Split(",").ToList();
                        int.TryParse(listPath.LastOrDefault(), out int j);
                        department.ParentId = j;
                    }
                    else
                    {
                        department.Path = string.Empty;
                    }
                    _departmentService.Update(department);

                    //update locale
                    _departmentModelFactory.UpdateLocales(department, model);
                    SuccessNotification(_localizationService.GetResource("Admin.Department.Updated"));
                    return(continueEditing ? RedirectToAction("Edit", new { id = department.Id }) : RedirectToAction("List"));
                }

                //prepare model
                model = _departmentModelFactory.PrepareModel(model, department);
                if (model.Path == string.Empty)
                {
                    model.Path = "0";
                }
                //if we got this far, something failed, redisplay form
                return(View(model));
            }
            catch (Exception exc)
            {
                ErrorNotification(exc);
                return(RedirectToAction("Edit", new { id = department.Id }));
            }
        }
コード例 #2
0
 /// <summary>
 /// 添加部门信息
 /// </summary>
 /// <param name="model">部门信息</param>
 /// <returns></returns>
 /// <remarks>是否更新成功</remarks>
 public bool AddDepartment(DepartmentModel model)
 {
     using (var dbContext = new MissionskyOAEntities())
     {
         var departmentEntity = model.ToEntity();
         departmentEntity.CreatedDate = DateTime.Now;
         departmentEntity.No          = "MSSKY";
         var entity = dbContext.Departments.Add(departmentEntity);
         dbContext.SaveChanges();
         return(true);
     }
 }
        public IActionResult Create(DepartmentModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(EmployeePermissionProvider.ManageDepartments))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var department = model.ToEntity();
                _employeeService.InsertDepartment(department);
                return(continueEditing
                    ? RedirectToAction(nameof(Edit), new { id = department.Id })
                    : RedirectToAction(nameof(List)));
            }

            //If we got this far, something failed, redisplay form
            return(View($"{Route}{nameof(Create)}.cshtml", model));
        }
コード例 #4
0
        public virtual IActionResult Create(DepartmentModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers))
            {
                return(AccessDeniedView());
            }
            model.HospitalId = _workContext.HospitalId;
            if (ModelState.IsValid)
            {
                model.UpdatedOnUtc = DateTime.UtcNow;
                model.CreatedOnUtc = DateTime.UtcNow;
                model.CreatedBy    = _workContext.CurrentCustomer.Id;
                model.UpdatedBy    = _workContext.CurrentCustomer.Id;
                var department = model.ToEntity <Department>();
                if (department.Path == null || department.Path == "0")
                {
                    department.Path     = string.Empty;
                    department.ParentId = 0;
                }
                else
                {
                    var listPath = department.Path.Split(",").ToList();
                    int.TryParse(listPath.LastOrDefault(), out int j);
                    department.ParentId = j;
                }
                _departmentService.Insert(department);

                //update locale
                _departmentModelFactory.UpdateLocales(department, model);
                //activity log
                //_customerActivityService.InsertActivity("AddNewCustomerRole",
                //    string.Format(_localizationService.GetResource("ActivityLog.AddNewCustomerRole"), customerRole.Name), customerRole);

                SuccessNotification(_localizationService.GetResource("Admin.Customers.CustomerRoles.Added"));

                return(continueEditing ? RedirectToAction("Edit", new { id = department.Id }) : RedirectToAction("List"));
            }
            //prepare model
            model = _departmentModelFactory.PrepareModel(model, null, true);
            //if we got this far, something failed, redisplay form
            return(View(model));
        }