public async Task <OpportunityAuthResponse> Update(OpportunityUpdateRequest request, IUser user) { var existing = await _opportunityService.GetById(request.Id, true); var toSave = _mapper.Map(request, existing); if (existing.OpportunityUser.Any(ou => ou.UserId == user.Id)) { var saved = await _opportunityService.Update(toSave, user); if (request.IsPosting) { if (user.EmailVerified == false) { throw new UnauthorizedAccessException(); } toSave.PublishedAt = DateTime.UtcNow; saved = await _opportunityService.Update(toSave, user); } var result = _mapper.Map <OpportunityAuthResponse>(saved); return(result); } else { throw new UnauthorizedAccessException(); } }
public void Update(OpportunityUpdateRequest model) { DataProvider.ExecuteNonQuery(GetConnection, "dbo.Opportunity_Update", inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@Id", model.Id); paramCollection.AddWithValue("@Name", model.Name); paramCollection.AddWithValue("@Description", model.Description); paramCollection.AddWithValue("@ContactPersonFirstName", model.ContactPersonFirstName); paramCollection.AddWithValue("@ContactPersonLastName", model.ContactPersonLastName); paramCollection.AddWithValue("@Email", model.Email); paramCollection.AddWithValue("@Phone", model.Phone); paramCollection.AddWithValue("@Address1", model.Address1); paramCollection.AddWithValue("@Address2", model.Address2); paramCollection.AddWithValue("@City", model.City); paramCollection.AddWithValue("@StateProvinceId", model.StateProvinceId); paramCollection.AddWithValue("@PostalCode", model.PostalCode); paramCollection.AddWithValue("@CountryId", model.CountryId); paramCollection.AddWithValue("@UserIdCreated", UserService.GetCurrentUserId()); paramCollection.AddWithValue("@DateTimePickerStart", model.DateTimeStart); paramCollection.AddWithValue("@DateTimePickerEnd", model.DateTimeEnd); } ); return; }
public async Task <IActionResult> Update(int id, [FromBody] OpportunityUpdateRequest model) { var user = await _authorizationUtil.GetUser(User); var updated = await _opportunityBusiness.Update(model, user); return(Ok(updated)); }
public HttpResponseMessage Update(OpportunityUpdateRequest model) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } _opportunity.Update(model); SuccessResponse response = new SuccessResponse(); return(Request.CreateResponse(HttpStatusCode.OK, response)); }