public async Task <IActionResult> PutPartner([FromRoute] string id, [FromBody] PartnerVm partnerVm) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != partnerVm.Id) { return(BadRequest()); } if (!string.IsNullOrEmpty(partnerVm.Image64)) { _SaveLogo(partnerVm.Image64, partnerVm.Id); } var partner = partnerVm.ToBase(); partner.UpdatedDate = DateTime.UtcNow; _context.Entry(partner).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PartnerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PostPartner([FromBody] PartnerVm partnerVm) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (string.IsNullOrEmpty(partnerVm.Image64)) { return(BadRequest(new { message = "Please set an image." })); } _SaveLogo(partnerVm.Image64, partnerVm.Id); var partner = partnerVm.ToBase(); _context.Partners.Add(partner); await _context.SaveChangesAsync(); return(CreatedAtAction("GetPartner", new { id = partner.Id }, partner)); }