public ActionResult Create(CompanyViewModel companyVM) { if (ModelState.IsValid && this.ValidateFile(companyVM.Logo) && this.ValidateFile(companyVM.Banner)) { Company company = new Company(); Regex rgx = new Regex("[^a-zA-Z0-9 -]"); string filename = ""; filename = string.Format("{0}-{1}{2}", companyVM.Name, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString()); filename = rgx.Replace(filename, ""); filename = filename.Replace(" ", ""); filename = filename.ToLower(); //save to image path company.BannerImagePath = this.SaveImage(companyVM.Banner, filename + companyVM.Banner.FileName.Substring(companyVM.Banner.FileName.LastIndexOf('.'))); company.LogoImagePath = this.SaveImage(companyVM.Logo, filename + companyVM.Logo.FileName.Substring(companyVM.Logo.FileName.LastIndexOf('.')), true); //map data company.Description = companyVM.Description; company.Name = companyVM.Name; company.TagLine = companyVM.TagLine; company.Type = companyVM.Type; company.Website = companyVM.Website; //save to db db.Companies.Add(company); db.SaveChanges(); return RedirectToAction("Index"); } return View(companyVM); }
public bool Delete(Company entity) { using (var db = ContextFactory.CreateContext()) { db.Companies.Remove(entity); db.SaveChanges(); } return true; }
public bool Update(Company entity) { throw new NotImplementedException(); }