public async Task <IActionResult> Edit(EditCompanyInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var comapany = this.mapper.Map <CreditCompany>(model);

            await this.creditCompaniesService.EditCompanyAsync(comapany);

            return(this.RedirectToAction("All"));
        }
Esempio n. 2
0
        public IActionResult Edit(EditCompanyInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            Company company = this.companiesService.GetCompanyById(model.Id);

            company.Name         = model.Name;
            company.CreationDate = model.CreationDate;

            this.companiesService.UpdateCompany(company);

            return(this.RedirectToAction("Details", new { @id = company.Id }));
        }
Esempio n. 3
0
        public IActionResult Edit(string id)
        {
            Company company = this.companiesService.GetCompanyById(id);

            if (company == null)
            {
                return(this.View("NotFound"));
            }

            EditCompanyInputModel model = new EditCompanyInputModel
            {
                Id           = company.Id,
                Name         = company.Name,
                CreationDate = company.CreationDate
            };

            return(this.View(model));
        }
Esempio n. 4
0
        public async Task <IActionResult> Edit(string id)
        {
            try
            {
                var companyDto = await this.companiesService.GetCompanyByIdAsync(id);

                var company = new EditCompanyInputModel
                {
                    Id     = companyDto.Id,
                    Name   = companyDto.Name,
                    Ticker = companyDto.Ticker,
                };

                return(this.View(company));
            }
            catch (Exception ex)
            {
                return(this.Redirect($"/Home/Error?message={ex.Message}"));
            }
        }
Esempio n. 5
0
        public async Task <IActionResult> Edit(EditCompanyInputModel company)
        {
            try
            {
                if (!this.ModelState.IsValid)
                {
                    this.TempData["InvalidEditModel"] = $"Some of fields you entered are invalid!";
                    return(this.View(company));
                }

                string editedCompanyName = await this.companiesService.EditAsync(company.Id, company.Ticker, company.Name);

                this.TempData["SuccessfullUpdatedCompany"] = $"Successfully updated company {editedCompanyName}!";

                List <CompanyViewModel> companies = await this.GetAllCompaniesWithDeletedAsync();

                return(this.View("Index", companies));
            }
            catch (Exception ex)
            {
                return(this.Redirect($"/Home/Error?message={ex.Message}"));
            }
        }
Esempio n. 6
0
        public async Task <IActionResult> Edit(EditCompanyInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            var company = this.companiesService.GetById <EditCompanyInputModel>(input.Id);

            if (!this.User.IsInRole(GlobalConstants.AdministratorRoleName) && user.Id != company.UserId)
            {
                return(this.Unauthorized());
            }

            string imagePath = input.LogoImage;

            if (input.LogoImageFile != null)
            {
                await this.DeleteImageFromCloudinaryAsync(imagePath);

                imagePath = await this.UploadImageToCloudinaryAsync(input.LogoImageFile);
            }

            await this.companiesService.EditById(
                input.Id,
                input.Name,
                input.Description,
                imagePath,
                input.OfficialSite,
                input.CategoryId);

            this.TempData["Edited"] = true;

            return(this.RedirectToAction(nameof(this.Details), new { id = input.Id }));
        }
Esempio n. 7
0
        public async Task EditPostShouldEditCompanySuccessfully()
        {
            // Arrange
            this.FillDatabase();
            this.editModel = new EditCompanyInputModel
            {
                Id     = "company1",
                Name   = "New Name",
                Ticker = "TsLNn",
            };

            // Act
            var result = await this.controller.Edit(this.editModel);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <IEnumerable <CompanyViewModel> >(viewResult.ViewData.Model);

            var editedCompany = this.db.Companies.FirstOrDefault(x => x.Id == "company1");

            Assert.Equal("company1", editedCompany.Id);
            Assert.Equal("New Name", editedCompany.Name);
            Assert.Equal("TSLNN", editedCompany.Ticker);
        }