예제 #1
0
        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("/"));
        }
예제 #2
0
        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("/"));
        }
예제 #3
0
        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);
        }
예제 #4
0
        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());
        }
예제 #5
0
        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);
        }