public IActionResult Put(int id, [FromBody] Model.Department updateDepartment)
        {
            updateDepartment.Id = id;
            var retval = repo.Update(updateDepartment);

            return(StatusCode(StatusCodes.Status200OK, retval));
        }
        public IActionResult PutDepartment(int id, Department department)
        {
            if (id != department.Id)
            {
                return(BadRequest());
            }

            try
            {
                _deptRepo.Update(department);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DepartmentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
 public IActionResult EditWithSubject([FromBody] Department dept)
 {
     if (ModelState.IsValid)
     {
         repo.Update(dept);
         return(Json(new { success = true }));
     }
     return(Json(new { success = false }));
 }
Пример #4
0
        public IActionResult Update(int departmentId, [FromBody] Department model)
        {
            if (model == null || departmentId != model.Id || !ModelState.IsValid)
            {
                return(BadRequest());
            }

            _repo.Update(model);
            return(CreatedAtAction("Update", model));
        }
Пример #5
0
        public async Task <IActionResult> PutDepartment([FromRoute] int id, [FromBody] Department department)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != department.Id)
            {
                return(BadRequest());
            }

            await _context.Update(department, id);



            return(NoContent());
        }
Пример #6
0
        public void UpdateAll(List <DepartmentFetched> departmentsFetched)
        {
            var departments = _repository.GetAll();

            // Delete should be cascade if it's necessary
            // foreach (var department in departments)
            // {
            //     if (!departmentsFetched.Select(v => v.Id).Contains(department.Code))
            //         _repository.Delete(department);
            // }
            foreach (var departmentFetched in departmentsFetched)
            {
                var foundDepartment = departments.SingleOrDefault(v => v.Code == departmentFetched.Id);
                if (foundDepartment == null)
                {
                    _repository.Add(departmentFetched.ToDepartment());
                }
                else
                {
                    var wasChanged = false;
                    var name       = departmentFetched.Name.Trim();
                    if (foundDepartment.Name != name)
                    {
                        foundDepartment.Name = name;
                        wasChanged           = true;
                    }
                    var shortName = departmentFetched.Reduction.Trim();
                    if (foundDepartment.ShortName != shortName)
                    {
                        foundDepartment.ShortName = shortName;
                        wasChanged = true;
                    }
                    if (foundDepartment.IsActive != departmentFetched.Enable)
                    {
                        foundDepartment.IsActive = departmentFetched.Enable;
                        wasChanged = true;
                    }
                    if (wasChanged)
                    {
                        _repository.Update(foundDepartment);
                    }
                }
            }
        }
Пример #7
0
        public void Update(
            int id,
            DepartmentRequest department)
        {
            if (department == null)
            {
                throw new ArgumentNullException(nameof(department));
            }
            var foundDepartment = _repository.GetById(id);

            if (foundDepartment == null)
            {
                throw new ArgumentNullException(nameof(foundDepartment));
            }

            foundDepartment.ShortName = department.ShortName;
            foundDepartment.LongName  = department.LongName;
            _repository.Update(foundDepartment);
        }