public async Task <BaseEntity> SaveAndReturnEntityAsync(PersonAlertCommentDto entityDto) { var personAlertComment = _mapper.Map <PersonAlertComment>(entityDto); if (entityDto.PersonAlert != null) { var personAlert = _repository.CRMContext.PersonAlerts.FirstOrDefaultAsync(x => x.Id == entityDto.PersonAlertId).Result; if (personAlert.AlertStatusId != entityDto.PersonAlert.AlertStatusId) { personAlert.AlertStatusId = entityDto.PersonAlert.AlertStatusId; await _repository.SaveAndReturnEntityAsync(personAlert); } personAlertComment.PersonAlert = null; } if (entityDto.Id == 0) { var loggedUsed = _repository.CRMContext.IdentityUserView.FirstOrDefault( x => x.Id == _repository.CRMContext.CurrentLoggedUserId); personAlertComment.CreatedBy = loggedUsed?.FirstName + " " + loggedUsed?.LastName; personAlertComment.CreatedOn = DateTime.Now; } var result = await _repository.SaveAndReturnEntityAsync(personAlertComment); result.SuccessMessage = "The data is saved successfully"; return(result); }
public async Task <PersonAlertCommentDto> PutPersonAlertComment(int id, PersonAlertCommentDto model) { var url = CRMApiUri + "/PersonAlertComment/" + id; var result = await PutRequestToApi(url, model); return(result); }
public async Task <PersonAlertCommentDto> PostPersonAlertComment(PersonAlertCommentDto model) { var url = CRMApiUri + "/PersonAlertComment"; var result = await PostRequestToApi(url, model); return(result); }
public IActionResult Save(PersonAlertCommentDto model) { bool success; model = model.Id == 0 ? _customerFacadeApiClient.PostPersonAlertComment(model).Result : _customerFacadeApiClient.PutPersonAlertComment(model.Id, model).Result; success = string.IsNullOrWhiteSpace(model.ErrorMessage); return(Json(new { success, message = success ? model.SuccessMessage : model.ErrorMessage })); }
public async Task <IActionResult> Put(int id, [FromBody] PersonAlertCommentDto personAlertCommentDto) { if (id == 0 || personAlertCommentDto.Id == 0) { return(StatusCode(StatusCodes.Status400BadRequest, "Id needs to be greater than 0.")); } return(await SaveAndReturnEntityAsync(async() => await _personAlertCommentService.SaveAndReturnEntityAsync(personAlertCommentDto))); }
public async Task <IActionResult> Post([FromBody] PersonAlertCommentDto personAlertCommentDto) { if (personAlertCommentDto.Id != 0) { return(StatusCode(StatusCodes.Status400BadRequest, "Identity insert is not permitted.")); } return(await SaveAndReturnEntityAsync(async() => await _personAlertCommentService.SaveAndReturnEntityAsync(personAlertCommentDto))); }
public IActionResult Create(int personAlertId) { var personAlert = _customerFacadeApiClient.GetPersonAlert(personAlertId).Result; PopulateLookupFields(personAlert); var personAlertComment = new PersonAlertCommentDto { PersonAlertId = personAlertId, PersonAlert = personAlert }; return(PartialView("Edit", personAlertComment)); }
public async Task <PersonAlertCommentDto> PutPersonAlertComment(int id, PersonAlertCommentDto model) { return(await _personAlertCommentApiClient.PutPersonAlertComment(id, model)); }
public async Task <PersonAlertCommentDto> PostPersonAlertComment(PersonAlertCommentDto model) { return(await _personAlertCommentApiClient.PostPersonAlertComment(model)); }
public async Task <int> SaveAsync(PersonAlertCommentDto personAlertComment) { var result = await SaveAndReturnEntityAsync(personAlertComment); return(result.Id); }