Beispiel #1
0
        public IActionResult Create()
        {
            var viewModel = new CreateIssueInputModel();

            viewModel.CategoriesItems = this.categoriesService.GetAllAsKeyValuePairs();
            return(this.View(viewModel));
        }
Beispiel #2
0
        public async Task GetCountShouldReturnCorrectCount()
        {
            var userId = "someId";

            this.citizensList.Add(new Citizen {
                Id = 1, UserId = userId
            });

            var inputModel = new CreateIssueInputModel
            {
                Title   = "Test Title",
                Address = new Web.ViewModels.Address.CreateAddressInputModel {
                    City = "Test", Number = 1, Street = "Test"
                },
                Description  = "TestTestTestTestTestTestTest",
                Tags         = "uaba daba du",
                CategoryId   = 2,
                TitlePicture = this.mockFile.Object,
                Attachments  = new List <IFormFile>(),
            };

            var roothPath = "wwwroot";

            await this.issuesService.CreateAsync(inputModel, userId, roothPath);

            var issueCount = this.issuesService.GetCount();

            Assert.Equal(this.issuesList.Count(), issueCount);
        }
Beispiel #3
0
        public async Task CreateAsync(CreateIssueInputModel input, string userId, string rootPath)
        {
            var citizenId = this.citizensService.GetByUserId(userId).Id;
            var address   = await this.addressesService.CreateAsync(input.Address);

            var issue = new Issue
            {
                Title       = input.Title,
                Description = input.Description,
                Address     = address,
                CategoryId  = input.CategoryId,
                StatusId    = 1,
                CreatorId   = citizenId,
            };

            // Add image to file system
            issue.Pictures.Add(await this.picturesService.CreateFileAsync(userId, rootPath, input.TitlePicture));

            // Add Attachments to file system
            if (input.Attachments != null)
            {
                foreach (var att in input.Attachments)
                {
                    var attExtension = Path.GetExtension(att.FileName);
                    if (!this.allowedAttachmentExtensions.Any(x => attExtension.EndsWith(x)))
                    {
                        throw new Exception($"Format should be .docx or .pdf!");
                    }

                    var attachment = new Attachment
                    {
                        AddedByUserId = userId,
                        Extension     = attExtension,
                    };

                    Directory.CreateDirectory($"{rootPath}/att/issues/");
                    var physicalPath = $"{rootPath}/att/issues/{attachment.Id}{attachment.Extension}";
                    using Stream attFileStream = new FileStream(physicalPath, FileMode.Create);
                    await att.CopyToAsync(attFileStream);

                    await this.attRepo.AddAsync(attachment);

                    var issueAttachment = new IssueAttachment
                    {
                        Attachment = attachment,
                        Issue      = issue,
                    };

                    await this.issueAttRepo.AddAsync(issueAttachment);
                }
            }

            await this.issuesRepo.AddAsync(issue);

            await this.issuesRepo.SaveChangesAsync();

            await this.issueTagsService.CraeteAsync(issue.Id, input.Tags);
        }
Beispiel #4
0
        public async Task GetCountByCategoryShouldReturnCorrectCount()
        {
            var userId = "someId";

            this.citizensList.Add(new Citizen {
                Id = 1, UserId = userId
            });

            var inputModel = new CreateIssueInputModel
            {
                Title   = "Test Title",
                Address = new Web.ViewModels.Address.CreateAddressInputModel {
                    City = "Test", Number = 1, Street = "Test"
                },
                Description  = "TestTestTestTestTestTestTest",
                Tags         = "uaba daba du",
                CategoryId   = 2,
                TitlePicture = this.mockFile.Object,
                Attachments  = new List <IFormFile>(),
            };

            var roothPath = "wwwroot";

            await this.issuesService.CreateAsync(inputModel, userId, roothPath);

            inputModel.CategoryId = 3;
            await this.issuesService.CreateAsync(inputModel, userId, roothPath);

            await this.issuesService.CreateAsync(inputModel, userId, roothPath);

            foreach (var issue in this.issuesList)
            {
                if (issue.CategoryId == 2)
                {
                    issue.Category = new Category {
                        Name = "Second"
                    };
                    continue;
                }

                issue.Category = new Category {
                    Name = "First"
                };
            }

            var issueCount = this.issuesService.GetCountByCateogry("Second");

            Assert.Equal(1, issueCount);
        }
        public HttpResponse Add(string carId, CreateIssueInputModel input)
        {
            if (!this.IsUserSignedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            if (string.IsNullOrEmpty(input.Description) || input.Description.Length < 5)
            {
                return(this.Error("Description is not valid."));
            }

            this._issueService.Create(carId, input.Description);
            return(this.Redirect($"/Issues/CarIssues?carId={carId}"));
        }
Beispiel #6
0
        public async Task <IActionResult> Create(CreateIssueInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                input.CategoriesItems = this.categoriesService.GetAllAsKeyValuePairs();
                return(this.View(input));
            }

            var rootPath = $"{this.environment.WebRootPath}";

            try
            {
                var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;
                await this.issuesService.CreateAsync(input, userId, rootPath);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
                input.CategoriesItems = this.categoriesService.GetAllAsKeyValuePairs();
                return(this.View(input));
            }

            return(this.Redirect("/"));
        }