Пример #1
0
        public ActionResult Create(Company company, HttpPostedFileBase file)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (file != null)
                    {
                        byte[] data = null;
                        using (Stream inputStream = file.InputStream)
                        {
                            MemoryStream memoryStream = inputStream as MemoryStream;
                            if (memoryStream == null)
                            {
                                memoryStream = new MemoryStream();
                                inputStream.CopyTo(memoryStream);
                            }
                            data = memoryStream.ToArray();
                        }
                        company.Logo     = data;
                        company.LogoType = file.ContentType;
                    }
                    company            = val.ValidateCompany(company);
                    company.IsDelete   = false;
                    company.CompanyKey = Guid.NewGuid();
                    db.Company.Add(company);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                return(View(company));
            }
            catch (Exception e)
            {
                return(View("Error", new HandleErrorInfo(e, "AdminLogin", "UserHome")));
            }
        }