public async Task <ActionResult> UpdatePhone(PhonePatch p) { if (p.PhoneName == "" || (p.Price == 0 && p.ImageUrl == "" && p.Score == 0)) { return(BadRequest()); } int phoneId = this._phoneService.GetPhoneIdByName(p.PhoneName); if (phoneId == 0) { return(NotFound()); } Phone phone = await this._phoneService.UpdatePhone(phoneId, p); return(new OkObjectResult(phone)); }
public async Task <Phone> UpdatePhone(int phoneId, PhonePatch p) { Phone phone = this.GetPhoneById(phoneId); if (p.Price != 0) { phone.Price = p.Price; } if (p.ImageUrl != "") { phone.ImageUrl = p.ImageUrl; } if (p.Score != 0) { phone.Score = p.Score; } this._context.Phones.Update(phone); await this._context.SaveChangesAsync(); return(phone); }