public async Task ReplyAGrieviance(GrievianceReply grieviance) { try { Grieviance grievianceToReply = await _ctx.Grieviances.FindAsync(grieviance.GrievianceId); grievianceToReply.HasBeenSeen = true; await _ctx.GrievianceReplies.AddAsync(grieviance); _ctx.Grieviances.Update(grievianceToReply); Notification notification = new Notification { HasBeenSeen = false, Message = grieviance.Message, UserId = grievianceToReply.UserId }; await _ctx.Notifications.AddAsync(notification); await _ctx.SaveChangesAsync(); return; } catch (Exception ex) { _logger.LogInformation($"There was an error {ex.Message}"); } }
// GET: Voters/Edit/5 public async Task <IActionResult> Edit(int id) { GrievianceReply reply = await _reply.GetGrievianceReplyById(id); if (reply == null) { return(NotFound()); } return(View(reply)); }
public async Task <IActionResult> Create(GrievianceReply reply) { if (!ModelState.IsValid) { return(RedirectToAction(nameof(Create))); } try { await _reply.ReplyAGrieviance(reply); return(RedirectToAction(nameof(Index))); } catch { return(View(nameof(HomeController.Error))); } }
public async Task <bool> UpdateGrevianceReplyById(GrievianceReply grieviance) { if (GrievianceReplyExists(grieviance.GrievianceId)) { try { _ctx.GrievianceReplies.Update(grieviance); await _ctx.SaveChangesAsync(); return(true); } catch (Exception ex) { _logger.LogInformation($"There was an error {ex.Message}"); return(false); } } return(false); }
public async Task <IActionResult> Edit(int id, GrievianceReply reply) { if (id != reply.GrievianceReplyId) { return(RedirectToAction(nameof(Edit), new { id })); } if (!ModelState.IsValid) { return(RedirectToAction(nameof(Edit), new { id })); } try { await _reply.UpdateGrevianceReplyById(reply); return(RedirectToAction(nameof(Index))); } catch { return(View(nameof(HomeController.Error))); } }