public IActionResult Create(IdNameDto dto) { if (dto == null) { return(NoContent()); } if (dummyList.Any(i => i.Id == dto.Id)) { return(BadRequest(ErrorDto.Create($"Item with id = {dto.Id} already exists."))); } dummyList.Add(dto); Uri uri = Helper.CombineRequestPath(this.Request, dto.Id.ToString()); return(Created(uri, dto)); }
public ActionResult Add(IdNameDto idName) { if (idName.Id <= 0) { IdNamesService.AddNew(idName); AdminLogService.AddNew($"添加基础数据:{idName.Name}"); return(Json(new AjaxResult { Result = true, Msg = "添加成功" })); } IdNamesService.Update(idName); AdminLogService.AddNew($"修改基础数据:{idName.Name}"); return(Json(new AjaxResult { Result = true, Msg = "修改成功" })); }
public IActionResult Update(IdNameDto dto) { if (dto == null) { return(NoContent()); } var found = dummyList.Where(i => i.Id == dto.Id).FirstOrDefault(); if (found == null) { return(NotFound(ErrorDto.Create($"Item with id = {dto.Id} do not exists."))); } dummyList.Remove(found); dummyList.Add(dto); Uri uri = Helper.CombineRequestPath(this.Request, dto.Id.ToString()); return(Created(uri, dto)); }
public long AddNew(IdNameDto model) { IdNameEntity idNameEntity = model.EntityMap(); idNameEntity.CreateDateTime = DateTime.Now; using (YersDbContext ctx = new YersDbContext()) { BaseService <IdNameEntity> bs = new BaseService <IdNameEntity>(ctx); if (bs.GetAll().Any(m => m.TypeName == idNameEntity.TypeName && m.Name == idNameEntity.Name)) { throw new ArgumentException("该数据已存在,请检查"); } ctx.IdNames.Add(idNameEntity); ctx.SaveChanges(); return(idNameEntity.Id); } }
public void Update(IdNameDto dto) { using (YersDbContext ctx = new YersDbContext()) { BaseService <IdNameEntity> bs = new BaseService <IdNameEntity>(ctx); bool exists = bs.GetAll().Any(m => m.TypeName == dto.TypeName && m.Name == dto.Name && m.Id != dto.Id);; if (exists) { throw new ArgumentException("该数据已存在,请检查"); } var model = bs.GetById(dto.Id); model.Name = dto.Name; model.TypeName = dto.TypeName; model.ImageSrc = dto.ImageSrc; model.Remark = dto.Remark; ctx.SaveChanges(); } }
public static IdNameEntity EntityMap(this IdNameDto model) { return(Mapper.Map <IdNameEntity>(model)); }