public IActionResult Report(int id) { var task = this.TaskService.ReportTaskById(id); if (task == null) { this.Model.Data["Error"] = "There is no task with that id"; return(this.RedirectToAction("/")); } var user = this.UserService.GetUserByUsername(this.Identity.Username); var reportModel = new CreateReportInputModel() { ReportedOn = DateTime.Now, Reporter = user, Task = task }; var rnd = new Random(); var percent = rnd.Next(0, 100); reportModel.Status = percent > 25 ? Status.Completed : Status.Archived; var report = this.ReportService.CreateReport(reportModel); if (report == null) { this.Model.Data["Error"] = "A problem occured during reporting task. Please try again or contact admin."; return(this.RedirectToAction("/")); } return(this.RedirectToAction("/")); }
public IHttpResponse Report(int id) { var task = this.TaskService.ReportTaskById(id); if (task == null) { return(this.BadRequestError("Invalid task id")); } var user = this.UserService.GetUserByUsername(this.User.Username); var reportModel = new CreateReportInputModel() { ReportedOn = DateTime.Now, Reporter = user, Task = task }; var rnd = new Random(); var percent = rnd.Next(0, 100); reportModel.Status = percent > 25 ? Status.Completed : Status.Archived; var report = this.ReportService.CreateReport(reportModel); if (report == null) { return(this.BadRequestError("A problem occured during reporting task. Please try again or contact admin.")); } return(this.Redirect("/")); }
public async Task <string> Create(CreateReportInputModel model) { if (model == null) { return(null); } var repot = new Report() { Description = model.Description, Title = model.Title, ReporterId = model.ReporterId, SuspectedUserId = model.SuspectedUserId, ImgUrl = model.ImgUrl, TypeId = model.TypeId }; this.repository.Add(repot); var r = await this.repository.SaveChangesAsync(); if (r > 0) { return(repot.Id); } return(null); }
public async Task <IActionResult> Post(CreateReportInputModel inputModel) { if (this.ModelState.IsValid) { var r = await this.service.Create(inputModel); if (r != "") { return(this.Ok(r)); } } return(this.Problem()); }
public Report CreateReport(CreateReportInputModel model) { var report = new Report() { ReportedOn = model.ReportedOn, ReporterId = model.Reporter.Id, TaskId = model.Task.Id, Status = model.Status }; this.db.Reports.Add(report); try { this.db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); return(null); } return(report); }