示例#1
0
        public IActionResult Create(CategoryIndexModel model)
        {
            var category = Mapper.Map <RequestCategory>(model.CategoryCreationBindingModel);
            //if (dbContext.RequestCategories.Any(c => c.Name == category.Name))
            //{
            //    this.TempData.Put("__Message", new MessageModel()
            //    {
            //        Type = MessageType.Warning,
            //        Message = "Category already exists"
            //    });

            //    return this.RedirectToAction("Index");
            //}

            Task added = this.service.AddAsync(category);

            if (added.IsFaulted)
            {
                return(this.BadRequest());
            }

            Task success = this.service.SaveChangesAsync();

            if (success.IsFaulted)
            {
                return(this.BadRequest());
            }

            alerter.AddMessage(MessageType.Success, "Category created successfully");

            return(this.RedirectToAction("Index"));
        }
        public async Task <IActionResult> Create(int reqId, string resol)
        {
            await this.requestService.SaveResolutionAsync(reqId, resol);

            alerter.AddMessage(MessageType.Success, $"Successfully saved resolution for request {reqId}");
            return(this.Redirect($"/Management/Requests/Manage?id={reqId}"));
        }
示例#3
0
        public async Task <IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var solution = Mapper.Map <Solution>(Model);

            solution.AuthorId = this.userManager.GetUserId(User);


            await this.solutionService.AddAsync(solution);

            if (Model.Attachments != null)
            {
                string path = await fileUploader.CreateAttachmentAsync(Model.Title, Model.Attachments, "Solutions");

                ICollection <SolutionAttachment> attachments = new List <SolutionAttachment>();

                foreach (var attachment in Model.Attachments)
                {
                    SolutionAttachment solutionAttachment = new SolutionAttachment
                    {
                        FileName   = attachment.FileName,
                        PathToFile = Path.Combine(path, attachment.FileName),
                        SolutionId = solution.Id
                    };
                    attachments.Add(solutionAttachment);
                }

                await this.attachmentService.AddRangeAsync(attachments);
            }

            await this.solutionService.SaveChangesAsync();

            alerter.AddMessage(MessageType.Success, "Solution created successfully");

            return(Redirect($"/Solutions/Details/{solution.Id}"));
        }