Ejemplo n.º 1
0
 public ActionResult Edit([Bind(Include = "D_ID,D_Name,Manager")] Department department)
 {
     if (ModelState.IsValid)
     {
         _db.Edit(department);
         return(RedirectToAction("Index"));
     }
     return(View(department));
 }
Ejemplo n.º 2
0
 /// <summary>
 ///  创建组织架构集合
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="entitys">组织架构集合</param>
 /// <returns></returns>
 public bool EditCollection(ref ValidationErrors validationErrors, IQueryable <Department> entitys)
 {
     try
     {
         if (entitys != null)
         {
             int count = entitys.Count();
             if (count == 1)
             {
                 return(this.Edit(ref validationErrors, entitys.FirstOrDefault()));
             }
             else if (count > 1)
             {
                 using (TransactionScope transactionScope = new TransactionScope())
                 {
                     repository.Edit(db, entitys);
                     if (count == repository.Save(db))
                     {
                         transactionScope.Complete();
                         return(true);
                     }
                     else
                     {
                         Transaction.Current.Rollback();
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return(false);
 }
Ejemplo n.º 3
0
        public BaseResponse DeleteLogicalDepartment(int id)
        {
            BaseResponse response = new BaseResponse();
            Department   model    = _departmentRepository.GetById(id);

            try
            {
                DepartmentQuery query = new DepartmentQuery();
                query.Keyword  = "";
                query.Active   = null;
                query.ParentId = id;

                BaseListResponse <SPGetDepartment_Result> lstChild = GetSubDepartmentNonSeft(query);
                var lstStaffs = _staffRepository.SearchStaffs(id, 1, "", null);
                if (lstChild.Data.Count() > 0)
                {
                    response.IsSuccess = false;
                    response.Message   = "Tồn tại đơn vị con. Xóa không thành công";
                }
                else if (lstStaffs.Count() > 0)
                {
                    response.IsSuccess = false;
                    response.Message   = "Tồn tại cán bộ thuộc đơn vị. Xóa không thành công";
                }
                else
                {
                    model.EditedOn = DateTime.Now;
                    model.Deleted  = true;
                    _departmentRepository.Edit(model);
                    _applicationLoggingRepository.Log("EVENT", "DELETE", "Department", model.Id.ToString(), "", "", model, "", HttpContext.Current.Request.UserHostAddress, model.CreatedBy);
                }
            }
            catch (Exception ex)
            {
                response.Message   = ex.Message;
                response.IsSuccess = false;
            }
            return(response);
        }