public async Task <ActionResult> ModifyBuyerDetails(ModifyBuyerDetailsRequest request) { request.BuyerId = this.GetRequestUserId(); Response response = await this.buyersManager.ModifyBuyerDetails(request); if (response.IsOperationSucceeded) { return(this.StatusCode(StatusCodes.Status200OK, response.SuccessOrFailureMessage)); } // at the moment return(this.StatusCode(StatusCodes.Status404NotFound, response.SuccessOrFailureMessage)); }
public async Task <Response> ModifyBuyerDetails(ModifyBuyerDetailsRequest request) { var buyer = await _context.Buyers.FindAsync(request.BuyerId).ConfigureAwait(false); if (buyer == null) { return(new Response() { IsOperationSucceeded = false, SuccessOrFailureMessage = BuyerNotFoundFailString }); } if (request.Address != null) { buyer.Address = request.Address; } if (request.PostalCode != null) { buyer.PostalCode = request.PostalCode; } if (request.PhoneNumber != null) { buyer.PhoneNumber = request.PhoneNumber; } if (request.Email != null) { buyer.Email = request.Email; } if (request.ProfilePicture != null) { buyer.ProfilePicture = request.ProfilePicture; } try { _context.Buyers.Update(buyer); await _context.SaveChangesAsync().ConfigureAwait(false); } catch (Exception ex) { return(new Response() { IsOperationSucceeded = false, SuccessOrFailureMessage = ex.Message }); } return(new Response() { IsOperationSucceeded = true, SuccessOrFailureMessage = this.getSuccessMessage() }); }