public ActionResult Users(DLAdmin admin, string save) { try { var Photo = Request.Files["Photo"]; string ImageName = Photo.FileName; string PhysicalPath = Server.MapPath("~/Content/Images/Photos/" + ImageName); Photo.SaveAs(PhysicalPath); admin.Photo = ImageName; if (!String.IsNullOrEmpty(save)) { List <DLAdmin> dallist = bal.LoadData(); DLAdmin dal = new DLAdmin(); foreach (var m in dallist) { if (m.Email == admin.Email) { TempData["Error"] = "Email already exists!!"; return(Redirect("/User/Users")); } } int i = bal.Register(admin, "Insert"); } else { int i = bal.Register(admin, "Update"); } return(Redirect("/User/Users")); } catch (Exception ex) { throw ex; } }
public ActionResult Login(DLAdmin ad, string ReturnUrl = "") { try { if (!string.IsNullOrEmpty(ad.Email) && !string.IsNullOrEmpty(ad.Password)) { if (bal.IsValid(ad.Email, ad.Password, "CheckValid")) { BLAdmin bal = new BLAdmin(); FormsAuthentication.SetAuthCookie(ad.Email, true); var dal = bal.LoadData(); foreach (var e in dal) { if (e.Email == ad.Email) { Session["Role"] = e.Role; Session["Photo"] = e.Photo; break; } } if (Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { return(Redirect("/Home/Dashboard")); } } else { TempData["Error"] = "Invalid Email Id Or Password"; } } else { TempData["Error"] = "Required Email Id Or Password"; } } catch (Exception ex) { throw ex; } return(View()); }