public async Task <IActionResult> Edit(string id, [FromForm] RankUpdateModel updateModel)
        {
            if (ModelState.IsValid)
            {
                var isEffected = await _rankService.UpdateAsync(id, updateModel);

                return(RedirectToAction(nameof(Index)));
            }

            return(View(updateModel));
        }
Esempio n. 2
0
 public async Task <ActionResult <RankDTO> > UpdateAsync([FromBody] RankDTO model)
 {
     try
     {
         return(Ok(await rankService.UpdateAsync(model)));
     }
     catch (NotFoundException e)
     {
         return(NotFound(new { Id = e.Key, e.Message }));
     }
     catch (ValidationException e)
     {
         return(BadRequest(e.ValidationErrors));
     }
 }
      public async Task <IActionResult> PutAsync(int id, [FromBody] Rank resource)
      {          // if Model is invalid show error message by using ModelState
          if (!ModelState.IsValid)
          {
              return(BadRequest(ModelState.GetErrorMessages()));
          }
          //get data form EmployeeAttendenceResource by id using AutoMapper
          //var rate=_mapper.Map<SaveRateResource,Rate>(resource);
          //update data by id
          var result = await _rankService.UpdateAsync(id, resource);

          //if updated data is null
          if (result == null)
          {
              return(BadRequest(result));
          }
          //get result data from SaveEmployeeResource after update data using automapper
          var rateResource = _mapper.Map <Rank, RankResource>(result.Rank);

          //show data
          return(Ok(rateResource));
      }