public ActionResult CreateCourseBrands(FormCollection collection, CourseBrands coursebrand) { try { if (Session["ClientId"] != null) { if (!Roles.IsUserInRole("CenterManager")) { if (Session["RegionId"] != null) { ViewData["Branches"] = Utilities.GetBranchNameList((int)Session["ClientId"], (int)Session["RegionId"]); } else { ViewData["Branches"] = Utilities.GetBranchNameList((int)Session["ClientId"]); } } else { if (Session["BranchId"] != null) { coursebrand.BranchId = (int)Session["BranchId"]; ViewData["Branches"] = Utilities.GetBlankBranchNameList(); } else { return(RedirectToAction("LogOff", "Account")); } } } else { if (Roles.IsUserInRole("SuperAdmin")) { return(RedirectToAction("List", "Client")); } } if (!ModelState.IsValid) { return(View()); } // TODO: Add insert logic here if (CourseModels.CreateCourseBrand(coursebrand) > 0) { return(RedirectToAction("CourseBrandList")); } else { return(View()); } } catch { return(View()); } }
public static int CreateCourseBrand(CourseBrands courseBrand) { try { using (VedantaEntities ve = new VedantaEntities()) { CourseBrands oldBrand = ve.CourseBrands.FirstOrDefault(cb => cb.BranchId == courseBrand.BranchId && courseBrand.Name.Equals(cb.Name, StringComparison.OrdinalIgnoreCase)); if (oldBrand == null) { ve.AddToCourseBrands(courseBrand); return(ve.SaveChanges()); } else { return(0); } } } catch (Exception) { return(0); } }