public async Task <int> UpdateGenderType(GenderTypeDto model) { var genderToUpdate = await _skinHubAppDbContext.GenderType.FindAsync(model.ID); if (genderToUpdate != null) { genderToUpdate.Name = model.Name; _skinHubAppDbContext.Entry(genderToUpdate).State = EntityState.Modified; await _skinHubAppDbContext.SaveChangesAsync(); return(model.ID); } return(0); }
public async Task <GenderTypeDto> GetGenderTypeByID(int id) { var genderTypeByID = await _skinHubAppDbContext.GenderType.FirstOrDefaultAsync(g => g.ID == id); if (genderTypeByID != null) { var model = new GenderTypeDto { ID = genderTypeByID.ID, Name = genderTypeByID.Name, // ColorType = genderTypeByID.ColorType }; return(model); } return(null); }
public async Task <IActionResult> Update([FromBody] GenderTypeDto model) { try { if (ModelState.IsValid) { var update = await _genderTypeServices.GetGenderTypeByID(model.ID); if (update != null) { await _genderTypeServices.UpdateGenderType(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")); } }