public ActionResult Edit(OrgBrand orgBrand, HttpPostedFileBase Logo) { try { if (Session["OrgId"] == null) { return(RedirectToAction("Signin", "Access")); } if ((int)Session["OrgId"] != 23) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if ((int)Session["OrgId"] == 23) { if (ModelState.IsValid) { var orgBrandInDb = db.OrgBrands.Include(f => f.Files).Single(c => c.OrgBrandId == orgBrand.OrgBrandId); orgBrandInDb.OrgBrandName = orgBrand.OrgBrandName; orgBrandInDb.OrgBrandButtonColour = orgBrand.OrgBrandButtonColour; if (Logo != null && Logo.ContentLength > 0) { if (orgBrandInDb.Files.Any(f => f.FileType == FileType.Logo)) { db.Files.Remove(orgBrandInDb.Files.First(f => f.FileType == FileType.Logo)); } var logo = new File { FileName = System.IO.Path.GetFileName(Logo.FileName), FileType = FileType.Logo, ContentType = Logo.ContentType }; using (var reader = new System.IO.BinaryReader(Logo.InputStream)) { logo.Content = reader.ReadBytes(Logo.ContentLength); } orgBrandInDb.Files = new List <File> { logo }; } db.Entry(orgBrandInDb).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } } } catch (Exception e) { Console.WriteLine(e); return(Redirect("~/ErrorHandler.html")); } return(new HttpStatusCodeResult(204)); }
public ActionResult Create(OrgBrand orgBrand, HttpPostedFileBase upload) { try { if (Session["OrgId"] == null) { return(RedirectToAction("Signin", "Access")); } if ((int)Session["OrgId"] != 23) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if ((int)Session["OrgId"] == 23) { if (ModelState.IsValid) { if (upload != null && upload.ContentLength > 0) { var avatar = new File { FileName = System.IO.Path.GetFileName(upload.FileName), FileType = FileType.Logo, ContentType = upload.ContentType }; using (var reader = new System.IO.BinaryReader(upload.InputStream)) { avatar.Content = reader.ReadBytes(upload.ContentLength); } orgBrand.Files = new List <File> { avatar }; } db.OrgBrands.Add(orgBrand); db.SaveChanges(); return(RedirectToAction("Index")); } } } catch (Exception e) { Console.WriteLine(e); return(View(orgBrand)); } return(View(orgBrand)); }
public ActionResult EditOrgBrand(int Id) { try { if (Session["OrgId"] == null) { return(RedirectToAction("Signin", "Access")); } if ((int)Session["OrgId"] != 23) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if ((int)Session["OrgId"] == 23) { if (Id != 0) { var rr = Session["OrgId"].ToString(); int i = Convert.ToInt32(rr); var edtorgbrand = db.OrgBrands .Include(f => f.Files) .Where(x => x.OrgBrandId == Id) .FirstOrDefault(); var edtorgBrand1 = new OrgBrand { OrgBrandId = edtorgbrand.OrgBrandId, OrgBrandName = edtorgbrand.OrgBrandName, OrgBrandButtonColour = edtorgbrand.OrgBrandButtonColour, }; return(PartialView("~/Views/Shared/PartialViewsForms/_EditOrgBrand.cshtml", edtorgBrand1)); } } } catch (Exception e) { Console.WriteLine(e); return(Redirect("~/ErrorHandler.html")); } return(new HttpStatusCodeResult(204)); }