public async Task <AlertCreateResponse> UpdateAlert(int alertId, Alert item, string userId) { var response = new AlertCreateResponse(); if (item.UserId != userId) { response.Message = "Bad request: Invalid userId"; return(response); } if (item.AlertId != alertId) { response.Message = "Bad request: Invalid alertId"; return(response); } //Checking if the user has an alert var get = await _alertRepository.GetAlert(alertId); if (get.UserId != userId || get.AlertId != alertId) { response.Message = "Alert not found"; return(response); } var result = await _alertRepository.UpdateAlert(item); return(result); }
public async Task <AlertCreateResponse> UpdateAlert(Alert item) { var response = new AlertCreateResponse(); _context.Entry(item).State = EntityState.Modified; var result = await _context.SaveChangesAsync(); if (result == 0) { response.Message = "Failed edition to db!"; } response.Id = item.AlertId; response.Message = "Successful edition!"; return(response); }
public async Task <AlertCreateResponse> AddAlert(Alert item, string userId) { var response = new AlertCreateResponse(); item.UserId = userId; item.AlertId = 0; //Parameters validation if (item.UserId == null) { response.Message = "User download error. "; } if (string.IsNullOrEmpty(item.Exchange)) { response.Message = response.Message + "Empty exchange. "; } if (item.Threshold == 0 & item.Threshold < 0) { response.Message = response.Message + "Empty Threshold. "; } if (string.IsNullOrEmpty(item.Currency)) { response.Message = response.Message + "Empty currency. "; } if (!string.IsNullOrEmpty(response.Message)) { return(response); } //Save alert var result = await _alertRepository.AddAlert(item); if (result != null) { response = result; } else { response.Message = "Adding failed"; } return(response); }