示例#1
0
        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();
            }
        }
示例#3
0
        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);
        }
示例#4
0
 public IHttpActionResult Update([FromBody] ClassUpdateModel classToUpdate, [FromUri] int classId)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     _service = new ClassService();
     _service.UpdateClass(classToUpdate, classId);
     return(Ok());
 }
示例#5
0
        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());
        }
示例#6
0
        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));
            }
        }
示例#7
0
        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));
        }
示例#8
0
 public Task <IResultModel> Update(ClassUpdateModel model)
 {
     return(_service.Update(model));
 }
示例#9
0
        public async Task <ClassUpdateModel> Update(string id, ClassUpdateModel classUpdate)
        {
            var classs = await _classService.Update(id, classUpdate);

            return(classs);
        }