示例#1
0
        public virtual ActionResult CreateCompany(CompanyAddViewModel model)
        {
            //1048576 Bytes == 1024 * 1024 KB == 1 MB ---> 1024
            if (ModelState.IsValid)
            {
                try
                {
                    if (model.Image != null)
                    {
                        if (model.Image.ContentLength > 0)
                        {
                            using (var img = Image.FromStream(model.Image.InputStream))
                            {
                                string fileName = TODO.CheckExistFile(Server.MapPath("~/Content/Images/Company/"), model.Image.FileName);
                                TODO.UploadImage(img, new Size(70, 70), Server.MapPath("~/Content/Images/Company/"), fileName);
                                model.ImageLogo = fileName;
                            }
                        }
                    }


                    model.Title = HelperTitle.GetTitle(Address: model.Address);

                    var company = new Company {
                        Address = model.Address, ImageLogo = model.ImageLogo, Explain = model.Explain, Name = model.Name, Title = model.Title
                    };
                    _companyService.Create(company);
                    if (_unitOfWork.SaveAllChanges() > 0)
                    {
                        return(RedirectToAction(MVC.admin.Company.ActionNames.DetailsCompany, new { Id = company.Id }));
                    }
                    else
                    {
                        TempData["createCompany"] = Helperalert.alert(new AlertViewModel {
                            Alert = AlertOperation.SurveyOperation(StatusOperation.FailInsert), Status = AlertMode.warning
                        });
                        return(View());
                    }
                }
                catch
                {
                    TempData["createCompany"] = Helperalert.alert(new AlertViewModel {
                        Alert = AlertOperation.SurveyOperation(StatusOperation.FailInsert), Status = AlertMode.warning
                    });
                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }
示例#2
0
 public void OnTestStarted()
 {
     driver = new ChromeDriver();
     driver.Manage().Window.Maximize();
     All_Pages           = new AllLinks(driver);
     Page_StatusCode     = new PageStatusCode();
     Helper_Title        = new HelperTitle(driver);
     Helper_H1           = new HelperH1(driver);
     Canonical_Helper    = new CanonicalHelper(driver);
     https_www_URLs      = new https_wwwURLs();
     Get_StatusCode301   = new GetStatusCode301();
     http_URLs           = new httpURLs();
     http_www_URLs       = new http_wwwURLs();
     slash_helper        = new SlashHelper();
     mixed_ContentHelper = new MixedContentHelper(driver);
     W3C_hel_per         = new W3C_helper();
 }
示例#3
0
        public virtual ActionResult UpdateCompany(CompanyEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var    company = _companyService.GetById(model.Id);
                string address = Server.MapPath("~/Content/Images/Company/");

                if (model.Image == null)
                {
                    if (company.ImageLogo != null)
                    {
                        TODO.DeleteImage(Path.Combine(address, company.ImageLogo));
                    }
                    company.ImageLogo = null;
                }
                else
                {
                    if (company.ImageLogo == null)
                    {
                    }
                    else
                    {
                        TODO.DeleteImage(Path.Combine(address, company.ImageLogo));
                    }

                    if (model.Image.ContentLength > 0)
                    {
                        using (var img = Image.FromStream(model.Image.InputStream))
                        {
                            string fileName = TODO.CheckExistFile(Server.MapPath("~/Content/Images/Company/"), model.Image.FileName);
                            TODO.UploadImage(img, new Size(70, 70), Server.MapPath("~/Content/Images/Company/"), fileName);
                            company.ImageLogo = fileName;
                        }
                    }
                }

                company.Explain = model.Explain;
                company.Name    = model.Name;

                if (company.Address != model.Address)
                {
                    company.Title   = HelperTitle.GetTitle(Address: model.Address);
                    company.Address = model.Address;
                }
                _companyService.Update(company);
                if (_unitOfWork.SaveAllChanges() > 0)
                {
                    return(RedirectToAction(MVC.admin.Company.ActionNames.DetailsCompany, new { Id = model.Id }));
                }
                else
                {
                    TempData["updateCompany"] = Helperalert.alert(new AlertViewModel {
                        Alert = AlertOperation.SurveyOperation(StatusOperation.FailUpdate), Status = AlertMode.warning
                    });
                    return(View());
                }
            }
            else
            {
                return(View(model));
            }
        }