예제 #1
0
        public async Task <PersonnelResponse> UpdateAsync(int id, Personnel category)
        {
            var existingPersonnel = await _personnelRepository.FindByIdAsync(id);

            if (existingPersonnel == null)
            {
                return(new PersonnelResponse("Personnel not found."));
            }

            existingPersonnel.Name    = category.Name;
            existingPersonnel.Surname = category.Surname;

            try
            {
                _personnelRepository.Update(existingPersonnel);
                await _unitOfWork.CompleteAsync();

                return(new PersonnelResponse(existingPersonnel));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new PersonnelResponse($"An error occurred when updating the personnel: {ex.Message}"));
            }
        }
예제 #2
0
        public IActionResult Put([FromBody] Model.Personnel personnel)
        {
            if (personnel == null)
            {
                return(BadRequest());
            }

            bool isSuccess = _personnelRepository.Update(ModelToTable(personnel));

            if (!isSuccess)
            {
                return(BadRequest());
            }

            return(Ok());
        }
예제 #3
0
        public async Task <IActionResult> Update(PersonnelVM vm)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var obj = (await objRep.Update(vm));

                    if (obj.Successed)
                    {
                        if (obj.ResultObject.PersonnelId > 0)
                        {
                            return(Ok(obj));
                        }
                        else
                        {
                            return(NotFound());
                        }
                    }
                    else
                    {
                        return(NotFound(obj));
                    }
                }
                catch (Exception ex)
                {
                    if (ex.GetType().FullName == "Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException")
                    {
                        return(NotFound());
                    }

                    return(BadRequest());
                }
            }

            return(BadRequest());
        }
예제 #4
0
 public string Put(int id, [FromBody] Personnel entity)
 {
     return(_dataRepository.Update(id, entity));
 }
예제 #5
0
 public void Update(Personnel_API entity)
 {
     _repo.Update(entity.ToDAL());
 }