public bool UpdateOne(ClassUpdateModel model, int id) { try { var classRoom = new ClassRoom() { Name = model.Name, BuildingID = model.BuildingID, RoomNO = model.RoomNO, TeacherID = model.TeacherID, ID = id }; Update(classRoom, id); Log.Information("Updated classRoom {0}", model.Name); return(true); } catch (System.Exception ex) { Log.Error(ex, "Exceptions occurred in classRoom update"); return(false); } }
public void UpdateClass(ClassUpdateModel classToUpdate, int classId) { Class entity = _ctx.Classes.Single(e => e.ClassId == classId); if (entity != null) { if (classToUpdate.UpdatedClassName != null) { entity.ClassName = classToUpdate.UpdatedClassName; } if (classToUpdate.UpdatedClassDescription != null) { entity.ClassDescription = classToUpdate.UpdatedClassDescription; } if (classToUpdate.UpdatedKeyAbilities != null) { entity.KeyAbilities = classToUpdate.UpdatedKeyAbilities; } if (classToUpdate.UpdatedSource != null) { entity.Source = classToUpdate.UpdatedSource; } _ctx.SaveChanges(); } }
public async Task <ClassUpdateModel> Update(string id, ClassUpdateModel p) { var classs = await GetById(id); _mapper.Map(p, classs); await _classes.ReplaceOneAsync(p => p.Id == id, classs); return(p); }
public IHttpActionResult Update([FromBody] ClassUpdateModel classToUpdate, [FromUri] int classId) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _service = new ClassService(); _service.UpdateClass(classToUpdate, classId); return(Ok()); }
public async Task <IResultModel> Update(ClassUpdateModel model) { var entity = await _repository.GetAsync(model.Id); if (entity == null) { return(ResultModel.NotExists); } _mapper.Map(model, entity); if (await _repository.Exists(entity)) { return(ResultModel.Failed($"类名称({entity.Name})已存在")); } using (var tran = _repository.BeginTransaction()) { if (await _repository.UpdateAsync(entity, tran)) { var methodEntity = await _classMethodRepository.GetByClass(model.Id, tran); if (methodEntity != null) { _mapper.Map(model.Method, methodEntity); //更新方法 if (await _classMethodRepository.UpdateAsync(methodEntity, tran)) { tran.Commit(); return(ResultModel.Success()); } } else { methodEntity = _mapper.Map <ClassMethodEntity>(model.Method); methodEntity.ClassId = entity.Id; //添加方法 if (await _classMethodRepository.AddAsync(methodEntity, tran)) { tran.Commit(); return(ResultModel.Success()); } } } } return(ResultModel.Failed()); }
public IActionResult Put([FromBody] ClassUpdateModel classRoom) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = unitOfWork.ClassRoom.UpdateOne(classRoom, classRoom.ID); return(Ok(new { result })); } catch (Exception ex) { Log.Error(ex, "Exceptions occurred in put classRoom api"); return(StatusCode(500, ex.Message)); } }
public async Task <IResultModel> Update(ClassUpdateModel model) { var entity = await _repository.GetAsync(model.Id); if (entity == null) { return(ResultModel.NotExists); } _mapper.Map(model, entity); if (await _repository.Exists(entity)) { return(ResultModel.Failed($"类名称({entity.Name})已存在")); } var result = await _repository.UpdateAsync(entity); return(ResultModel.Result(result)); }
public Task <IResultModel> Update(ClassUpdateModel model) { return(_service.Update(model)); }
public async Task <ClassUpdateModel> Update(string id, ClassUpdateModel classUpdate) { var classs = await _classService.Update(id, classUpdate); return(classs); }