예제 #1
0
        /// <summary>
        /// 修改公司信息数据
        /// </summary>
        public AjaxResult Update(TbDepartment dep, bool isApi = false)
        {
            if (dep == null)
            {
                return(AjaxResult.Warning("参数错误"));
            }
            var BmNameCount = Db.Context.From <TbDepartment>().Where(d => d.DepartmentName == dep.DepartmentName && d.DepartmentCode != dep.DepartmentCode && d.CompanyCode == dep.CompanyCode).ToList().Count;

            if (BmNameCount > 0)
            {
                return(AjaxResult.Warning("部门名称重复!"));
            }
            try
            {
                //var model = MapperHelper.Map<TbDepartment, TbDepartment>(dep);
                //var count = Repository<TbDepartment>.Update(model,isApi);
                //if (count <= 0)
                //{
                //    return AjaxResult.Error();
                //}
                Repository <TbDepartment> .Update(dep, p => p.DepartmentCode == dep.DepartmentCode, isApi);

                return(AjaxResult.Success());
            }
            catch (Exception e)
            {
                return(AjaxResult.Error(e.ToString()));
            }
        }
        public ActionResult Update(VMDepartment vmdepartment)
        {
            TbDepartment department = unitOfWork.Departments.Get(vmdepartment.Id);

            department.Name = vmdepartment.Name;
            unitOfWork.Complete();
            return(Ok(vmdepartment));
        }
        public ActionResult Add(VMDepartment vmdepartment)
        {
            TbDepartment department = mapper.Map <VMDepartment, TbDepartment>(vmdepartment);

            unitOfWork.Departments.Add(department);
            unitOfWork.Complete();
            vmdepartment.Id = department.Id;
            return(Ok(vmdepartment));
        }
        public ActionResult Delete(int id)
        {
            TbDepartment department = unitOfWork.Departments.Get(id);

            if (department == null)
            {
                return(NotFound());
            }
            unitOfWork.Departments.Remove(department);
            unitOfWork.Complete();
            return(Ok());
        }
예제 #5
0
 /// <summary>
 /// 新增公司信息 Or 修改公司信息
 /// </summary>
 /// <param name="company"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public ActionResult SubmitForm(TbDepartment company, string type)
 {
     if (type == "add")
     {
         var data = dit.Insert(company);
         return(Content(data.ToJson()));
     }
     else
     {
         var data = dit.Update(company);
         return(Content(data.ToJson()));
     }
 }