public async Task <int> UpdateColorType(ColorTypeDto model) { var colorToUpdate = await _skinHubAppDbContext.ColorType.FindAsync(model.ID); if (colorToUpdate != null) { colorToUpdate.Name = model.Name; _skinHubAppDbContext.Entry(colorToUpdate).State = EntityState.Modified; await _skinHubAppDbContext.SaveChangesAsync(); return(model.ID); } return(0); }
public async Task <ColorTypeDto> GetColorTypeByID(int id) { var colorTypeByID = await _skinHubAppDbContext.ColorType.Include(c => c.GenderType).FirstOrDefaultAsync(g => g.ID == id); if (colorTypeByID != null) { var model = new ColorTypeDto { ID = colorTypeByID.ID, Name = colorTypeByID.Name, GenderTypeID = colorTypeByID.GenderTypeID, GenderType = colorTypeByID.GenderType.Name, }; return(model); } return(null); }
public async Task <IActionResult> Update([FromBody] ColorTypeDto model) { try { if (ModelState.IsValid) { var update = await _colorTypeServices.GetColorTypeByID(model.ID); if (update != null) { await _colorTypeServices.UpdateColorType(model); return(Ok($"{model.Name} updated Successfully")); } } return(BadRequest("Update failed, Please try again")); } catch (Exception ex) { return(BadRequest($"{ex.Message}, Error! Your task failed, Please try again")); } }