public Result Get([FromBody]Announce value) { var r = new Result(); try { if (null == value) throw new Exception("未提交参数"); using (var context = new GZJContext()) { var announce = context.Announces.SingleOrDefault(t => t.Id == value.Id); if (announce == null) throw new Exception("该通知信息并不存在"); r.success = true; r.data = new { title=announce.Title, content=announce.Content, pubdate=announce.PubDate, pubusername=announce.PubUser.UserName }; } } catch (Exception ex) { r.message = ex.Message; } return r; }
internal void Update(string action, GZJContext context) { if (ParentId < 1) ParentId = null; var entity = context.HouseStructures.SingleOrDefault(t => t.Id == Id || t.HouseStructureName == HouseStructureName); if (action == "addnew") { if (entity != null) throw new Exception("该房屋结构信息已存在"); context.HouseStructures.Add(this); } else if (action == "edit") { if (entity == null) throw new Exception("该房屋信息并不存在!"); entity.ParentId = ParentId; entity.Memo = Memo; entity.HouseStructureName = HouseStructureName; } else if (action == "remove") { if (entity == null) throw new Exception("该房屋信息并不存在!"); if (entity.Houses.Count > 0) throw new Exception("有多个房源信息使用此房屋结构,请先更改原来的房源信息!"); context.HouseStructures.Remove(entity); } }
public List<dynamic> GetList([FromBody]LeaseFamily value) { var list = new List<dynamic>(); int leaseholderid = value == null ? 0 : value.LeaseHolderId; try { using (var context = new GZJContext()) { var arr = from t in context.LeaseFamilies select t; arr = from t in arr where t.LeaseHolderId == leaseholderid select t; arr.ToList() .ForEach(t => { list.Add(t.DTO()); }); } } catch (Exception ex) { throw ex; } return list; }
public Result Get([FromBody]HouseCategory value) { var r = new Result(); try { using (var context = new GZJContext()) { var entity = context.HouseCategories.SingleOrDefault(t => t.Id == value.Id); if (null == entity) throw new Exception("数据不存在"); r.data = new { categoryname=entity.CategoryName, id=entity.Id, parentid=entity.ParentId, memo=entity.Memo }; } r.success = true; r.message = ""; } catch (Exception ex) { r.message = ex.Message; } return r; }
public Result Get([FromBody]Leaseholder dto) { var r = new Result(); try { if (dto == null) throw new Exception("未指定参数"); using (var context = new GZJContext()) { var s = (from t in context.Leaseholders where t.Id==dto.Id select t).SingleOrDefault(); if (s == null) throw new Exception("未找到承租人信息"); r.success = true; r.data = s.DTO(); } } catch (Exception ex) { r.message = ex.Message; } return r; }
public static IEnumerable<Neighborhood> GetChildren(int pid,GZJContext context) { var query = from t in context.Neighborhoods where t.ParentId == pid select t; return query.ToList().Concat(query.ToList().SelectMany(t => GetChildren(t.Id,context))); }
internal void Update(string action, GZJContext context) { if (action == "addnew") { this.PubDate = DateTime.Now; context.Announces.Add(this); } else if (action == "edit") { var _entity = context.Announces.SingleOrDefault(t => t.Id == Id); if (_entity != null) { _entity.Content = Content; _entity.Title = Title; _entity.PubDate = DateTime.Now; } } else if (action == "remove") { var _entity = context.Announces.SingleOrDefault(t => t.Id == Id); if(_entity!=null) { context.Announces.Remove(_entity); } } }
public static IEnumerable<HouseCategory> GetChildren(int pid,GZJContext context) { var query = from t in context.HouseCategories where t.ParentId == pid select t; return query.ToList() .Concat(query.ToList().SelectMany(t => GetChildren(t.Id, context))); }
public GridWrap<dynamic> GetHouses([FromBody]JObject value) { var r = new GridWrap<dynamic>(); try { dynamic arg = value; if (null == arg) throw new Exception("未指定的参数"); int leaseholderid = 0; DateTime? enddate =null; DateTime _enddate=new DateTime(); foreach (JProperty prop in arg) { if (prop.Name == "leaseholderid") int.TryParse(prop.Value.ToString(), out leaseholderid); if(prop.Name=="enddate") { if (DateTime.TryParse(prop.Value.ToString(), out _enddate)) enddate = _enddate; } } using (var context = new GZJContext()) { var arr = from t in context.LeaseHistories select t; if (leaseholderid > 0) arr = from t in arr where t.LeaseHolderId == leaseholderid select t; if (enddate.HasValue) arr = from t in arr where t.EndDate.HasValue && t.EndDate <= enddate.Value select t; else arr = from t in arr where !t.EndDate.HasValue select t; arr = from t in arr orderby t.StartDate descending select t; r.total = arr.Count(); arr.ToList() .ForEach(t => { r.rows.Add(t.House.DTO()); }); } } catch (Exception ex) { r.message = ex.Message; } return r; }
internal void Update(string action, GZJContext context) { var _entity = context.Departments.SingleOrDefault(t =>t.Id==Id); if(action=="addnew"||action=="edit") { if(string.IsNullOrWhiteSpace(DepartmentName)) throw new Exception("岗位名称不能为空"); if(CompanyId<=0) throw new Exception("公司名称不能为空"); } if (action == "addnew") { if (_entity != null) throw new Exception("该岗位当前已存在"); _entity=context.Departments.SingleOrDefault(t=>t.DepartmentName==DepartmentName); if(_entity!=null) throw new Exception("该岗位当前已存在"); _entity = new Department { CompanyId = CompanyId, DepartmentName = DepartmentName, Memo = Memo, ContactPhone=ContactPhone }; context.Departments.Add(_entity); } else if (action == "edit") { if (_entity == null) throw new Exception("该岗位当前并不存在"); _entity.CompanyId = CompanyId; _entity.DepartmentName = DepartmentName; _entity.ContactPhone = ContactPhone; _entity.Memo = Memo; } else if (action == "remove") { if (_entity.Users.Count > 0) throw new Exception("该岗位下含有多个用户,请先指定用户为其他岗位!"); if(_entity==null) throw new Exception("该岗位当前并不存在"); context.Departments.Remove(_entity); } }
public Result AddNew([FromBody]Rent value) { var r = new Result(); try { using (var context = new GZJContext()) { value.Update("addnew", context); context.SaveChanges(); r.success = true; r.message = string.Format("该租金标准已成功添加!"); } } catch (Exception ex) { r.message = ex.Message; } return r; }
public Result Edit([FromBody]HouseCategory value) { var r = new Result(); try { using (var context = new GZJContext()) { value.Update("edit", context); context.SaveChanges(); } r.success = true; r.message = string.Format("[ {0} ]类别已经成功更新",value.CategoryName); } catch (Exception ex) { r.message = ex.Message; } return r; }
public Result AddNew([FromBody]Company value) { var r = new Result(); try { using (var context = new GZJContext()) { value.Update("addnew", context); context.SaveChanges(); } r.success = true; r.message = string.Format("[ {0} ]已成功添加", value.CompanyName); } catch (Exception ex) { r.message = ex.Message; } return r; }
public Result Edit([FromBody]Policy value) { var r = new Result(); try { using (var context = new GZJContext()) { value.Update("edit", context); context.SaveChanges(); r.message = string.Format("权限修改成功"); r.success = true; } } catch (Exception ex) { r.message = ex.Message; } return r; }
public Result AddNew([FromBody]House value) { var r = new Result(); try { using (var context = new GZJContext()) { value.Update("addnew", context); context.SaveChanges(); } r.message = string.Format("[ {0} ]房源信息已经更新",value.HouseNo); r.success = true; } catch (Exception ex) { r.message = ex.Message; } return r; }
internal void Update(string action, GZJContext context) { if (action == "addnew" || action == "edit") { if (string.IsNullOrWhiteSpace(PolicyNo)) throw new Exception("权限不能为空"); if (string.IsNullOrWhiteSpace(PolicyName)) throw new Exception("权限名称不能为空!"); if (string.IsNullOrWhiteSpace(GroupName)) throw new Exception("权限组名称不能为空!"); } var _entity = context.Policies.SingleOrDefault(t => t.PolicyNo == PolicyNo); if (action == "addnew") { if (_entity != null) throw new Exception("该权限代码已存在"); _entity = context.Policies.SingleOrDefault(t => t.PolicyName == PolicyName); if (_entity != null) throw new Exception("该权限名称已存在"); _entity = new Policy { PolicyNo = PolicyNo, PolicyName = PolicyName, GroupName = GroupName }; context.Policies.Add(_entity); } else if (action == "edit") { if (_entity == null) throw new Exception("该权限代码不存在"); _entity.PolicyName = PolicyName; _entity.PolicyNo = PolicyNo; _entity.GroupName = GroupName; } else if(action=="remove") { if (_entity == null) throw new Exception("该权限代码不存在"); context.Policies.Remove(_entity); } }
public Result Get([FromBody]Rent value) { var r = new Result(); try { using (var context = new GZJContext()) { var rent = context.Rents.SingleOrDefault(t => t.Id == value.Id); if (rent == null) throw new Exception("未找到租金标准信息"); r.data = rent.DTO(); r.success = true; } } catch (Exception ex) { r.message = ex.Message; } return r; }
public Result Get([FromBody]Policy value) { var r = new Result(); try { using (var context = new GZJContext()) { var s = context.Policies.SingleOrDefault(t =>value.PolicyNo==t.PolicyNo); if (null == s) throw new Exception("权限不存在"); r.success = true; r.data = s.DTO(); } } catch (Exception ex) { r.message = ex.Message; } return r; }
public dynamic Get([FromBody]Company value) { var r = new Result(); try { using(var context=new GZJContext()) { var s = context.Companies.SingleOrDefault(t => t.Id == value.Id); if (null == s) throw new Exception("所属公司并不存在"); r.data = s.DTO(); r.success = true; } } catch (Exception ex) { r.message = ex.Message; } return r; }
public Result Get([FromBody]HouseStructure value) { var r = new Result(); try { using (var context = new GZJContext()) { var entity = context.HouseStructures.SingleOrDefault(t => t.Id == value.Id); if (entity == null) throw new Exception("未找到对应的实体对象"); r.data = entity.DTO(); r.success = true; } } catch (Exception ex) { r.message = ex.Message; } return r; }
public Result Get([FromBody]Department value) { var r = new Result(); try { using (var context = new GZJContext()) { var s = context.Departments.SingleOrDefault(t => t.Id == value.Id); if (null == s) throw new Exception("数据并不存在"); r.data = s.DTO(); r.success = true; } } catch (Exception ex) { r.message = ex.Message; } return r; }
public Result Edit([FromBody]HouseStructure value) { var r = new Result(); try { using (var context = new GZJContext()) { value.Update("edit", context); context.SaveChanges(); r.message = string.Format("[{0}]已经更新成功", value.HouseStructureName); r.success = true; } } catch (Exception ex) { r.message = ex.Message; } return r; }
public Result Edit([FromBody]Neighborhood value) { var r = new Result(); try { if (value == null) throw new Exception("无提交参数"); using (var context = new GZJContext()) { value.Update(context, "edit"); context.SaveChanges(); r.success = true; r.message = string.Format("[ {0} ] 信息已成功更新", value.NeighborhoodName); } } catch (Exception ex) { r.message = ex.Message; } return r; }
public Result Edit([FromBody]Leaseholder leaseholder) { var r = new Result(); try { if (leaseholder == null) throw new Exception("提交参数不能为空"); using (var context = new GZJContext()) { leaseholder.Update("edit", context); context.SaveChanges(); r.success = true; r.message = string.Format("[ {0} ] 承租人信息已成功更新", leaseholder.UserName); } } catch (Exception ex) { r.message = ex.Message; } return r; }
public Result Edit([FromBody]Announce announce) { var r = new Result(); try { if (announce == null) throw new Exception("未提交参数"); using (var context = new GZJContext()) { announce.Update("edit", context); context.SaveChanges(); r.success = true; r.message = "该通知信息已成功更新"; } } catch (Exception ex) { r.message = ex.Message; } return r; }
public Result AddNew([FromBody]User value) { var r = new Result(); try { if (value == null) throw new Exception("参数不能为空"); using (var context = new GZJContext()) { value.Update(context, "addnew"); context.SaveChanges(); r.success = true; r.message = string.Format("[ {0} ]用户的信息已成功更新", value.UserCode); } } catch (Exception ex) { r.message = ex.Message; } return r; }
public Result ChangePass([FromBody]User value) { var r = new Result(); try { using (var context = new GZJContext()) { var user = context.Users.SingleOrDefault(t => t.UserCode == value.UserCode && t.UserPass == value.UserPass); if (null != user) throw new Exception("用户名或者密码不正确"); user.UserPass = value.UserPass; context.SaveChanges(); r.success = true; r.message = string.Format("用户密码已成功更新,下次登陆请启用新的密码"); } } catch (Exception ex) { r.message = ex.Message; } return r; }
internal void Update(string action, GZJContext context) { var entity = context.Companies .SingleOrDefault(t => t.Id == Id); if (action == "addnew") { if (null != entity) throw new Exception("该公司名称已存在"); entity = new Company { CompanyName=CompanyName, Memo=Memo, Address=Address, ContactPhone=ContactPhone, ZipCode=ZipCode }; context.Companies.Add(entity); } else if (action == "edit") { if (null == entity) throw new Exception("该公司信息并不存在"); entity.CompanyName = CompanyName; entity.Memo = Memo; entity.ContactPhone = ContactPhone; entity.ZipCode = ZipCode; entity.Address = Address; } else if (action == "remove") { if (null == entity) throw new Exception("该公司信息并不存在"); if (entity.Departments.Count > 0) throw new Exception("该公司下属多个部门,请先删除部门信息"); if (entity.Houses.Count > 0) throw new Exception("该公司下有多处房源信息,请先将房源归属设为其他公司"); context.Companies.Remove(entity); } }
public Result Get([FromBody]House value) { var r = new Result(); try { if (value == null) throw new Exception("未提交参数信息"); using (var context = new GZJContext()) { var entity = context.Houses.SingleOrDefault(t => t.Id == value.Id); if (null == entity) throw new Exception("未查询到相关房源信息"); r.success = true; r.data = entity.DTO(); } } catch (Exception ex) { r.message = ex.Message; } return r; }
public void Update(string action, GZJContext context) { var entity = context.LeaseFamilies.SingleOrDefault(t => t.Id == Id); if (action == "addnew") { context.LeaseFamilies.Add(this); } else if (action == "edit") { if (null == entity) throw new Exception("成员信息为空"); entity.UserName = UserName; entity.Age = Age; entity.CardNo = CardNo; entity.BusinessName = BusinessName; entity.RegisterDate = RegisterDate; entity.Sex = Sex; } else if (action == "remove") { context.LeaseFamilies.Remove(entity); } }