public override JsonResult <RestResponseDto> Post(ProjectEntity entity) { RestResponseDto res = new RestResponseDto(); try { Repository.BeginTran(); var user = (StaffEntity)WebHelper.GetSessionObj(WebHelper.USER_LOGIN_SESSION); entity.UserID = user.ID; entity.CompanyID = user.CompanyID; entity.CreateUser = user.Name; entity.CreateDate = DateTime.Now; Repository.Insert(entity); res.Entitys = new object[] { Repository.QueryFirst <ProjectEntity>(x => x.ID == entity.ID) }; Repository.Commit(); res.Success = true; } catch (Exception ex) { Repository.Rollback(); res.Success = false; res.Message = ex.Message; Log.Error(ex); } return(Json <RestResponseDto>(res)); }
public virtual JsonResult BatchHanlde([FromBody] BatchModel <T> batchModel, [FromServices] IRepositoryBase repository) { RestResponseDto res = new RestResponseDto(); var groups = batchModel.Entitys.GroupBy(x => x._state); foreach (var group in groups) { group.ToList().ForEach(model => { ReflectionUtil.TrimString(model); Validate(model); }); switch (group.Key) { case "added": repository.Insert <T>(group.ToArray()); break; case "modified": repository.Update <T>(group.ToArray()); break; } } res.Success = true; return(Json(res)); }
public virtual JsonResult <RestResponseDto> Delete(long id) { RestResponseDto res = new RestResponseDto(); try { Repository.BeginTran(); var entity = Repository.QueryFirst <T>(x => x.ID == id); if (entity == null) { throw new Exception(string.Format("不存在ID为[{0}]的对象!url:{1}", id, Request.RequestUri.AbsolutePath)); } entity.StatusEnum = BaseEntityStatus.Delete; Repository.Delete(entity); Repository.Commit(); res.Success = true; } catch (Exception ex) { Repository.Rollback(); res.Success = false; res.Message = ex.Message; Log.Error(ex); } return(Json <RestResponseDto>(res)); }
public virtual JsonResult Update(T entity, string[] modified) { RestResponseDto res = new RestResponseDto(); Repository.Update <T>(entity, modified); res.Entitys = new object[] { Repository.QueryFirst <T>(x => x.ID == entity.ID) }; res.Success = true; return(MyJson(res)); }
public virtual JsonResult Create(T entity) { RestResponseDto res = new RestResponseDto(); Repository.Insert(entity); res.Entitys = new object[] { Repository.QueryFirst <T>(x => x.ID == entity.ID) }; res.Success = true; return(MyJson(res)); }
public IActionResult GetNavigationTree() { RestResponseDto res = new RestResponseDto(); var list = _menuService.Repository.GetQueryExp <MenuEntity>(null).ToArray(); res.Data = list; res.Success = true; return(Json(res)); }
public virtual JsonResult Get(long id, string include) { RestResponseDto res = new RestResponseDto(); var includes = string.IsNullOrEmpty(include) ? null : include.Split(new char[] { ',' }); T entity = Repository.QueryFirst <T>(x => x.ID == id, includes); res.Entitys = new object[] { entity }; res.Success = true; return(MyJson(res)); }
public virtual JsonResult Single([FromForm] SingleModel singleModel, [FromServices] IRepositoryBase repository) { RestResponseDto res = new RestResponseDto(); T entity = repository.QueryFirst <T>(x => x.Id == singleModel.Id, singleModel.Include); res.Data = new object[] { entity }; res.Success = true; return(Json(res)); }
public virtual JsonResult Update([FromBody] UpdateModel <T> updateModel, [FromServices] IRepositoryBase repository) { RestResponseDto res = new RestResponseDto(); ReflectionUtil.TrimString(updateModel.Entity); Validate(updateModel.Entity); repository.Update <T>(updateModel.Entity); res.Success = true; return(Json(res)); }
public virtual JsonResult Create([FromBody] CreateModel <T> createModel, [FromServices] IRepositoryBase repository) { var entity = createModel.Entity; RestResponseDto res = new RestResponseDto(); ReflectionUtil.TrimString(entity); Validate(entity); repository.Insert(entity); res.Data = new object[] { repository.QueryFirst <T>(x => x.Id == entity.Id) }; res.Success = true; return(Json(res)); }
public virtual JsonResult Get(long id, string include) { RestResponseDto res = new RestResponseDto(); try { var includes = string.IsNullOrEmpty(include) ? null : include.Split(new char[] { ',' }); T entity = Repository.QueryFirst <T>(x => x.ID == id, includes); res.Entitys = new object[] { entity }; res.Success = true; } catch (Exception ex) { res.Success = false; res.Message = ex.Message; Log.Error(ex); } return(MyJson(res)); }
public virtual JsonResult Update(T entity) { RestResponseDto res = new RestResponseDto(); try { Repository.BeginTran(); Repository.Update <T>(entity); res.Entitys = new object[] { Repository.QueryFirst <T>(x => x.ID == entity.ID) }; Repository.Commit(); res.Success = true; } catch (Exception ex) { Repository.Rollback(); res.Success = false; res.Message = ex.Message; Log.Error(ex); } return(MyJson(res)); }
public override JsonResult Add(ModelEntity entity) { RestResponseDto res = new RestResponseDto(); try { Repository.BeginTran(); entity.CreateUser = ((StaffEntity)WebHelper.GetSessionObj(WebHelper.USER_LOGIN_SESSION)).Name; entity.CreateDate = DateTime.Now; entity.LastUpdate = DateTime.Now; Repository.Insert(entity); res.Entitys = new object[] { Repository.QueryFirst <ModelEntity>(x => x.ID == entity.ID) }; Repository.Commit(); res.Success = true; } catch (Exception ex) { Repository.Rollback(); res.Success = false; res.Message = ex.Message; Log.Error(ex); } return(MyJson(res)); }