public ActionResult DoLogin(FSCLogin objLogin) { string msgType = "Error"; string msg = string.Empty; try { if (ModelState.IsValid) { ClsLogin objClsLogin = new ClsLogin(); FSCLogin objLoginDetail = objClsLogin.AuthenticateUser(objLogin.Email); if (objLoginDetail != null && objLoginDetail.UserId > 0) { if (objLoginDetail.Password == FSCSecurity.EncryptPassword(objLogin.Password)) { //Initialise Session if (FSCWebRespository.InitialiseSession(objLoginDetail.UserId)) { FormsAuthentication.SetAuthCookie(objLogin.Email.ToUpper(), true); return(RedirectToAction("../Home/Home")); } else { msg = "Technical Error!"; } } else { msg = "Invalid Password!"; } } else { msg = "Invalid User"; } ViewBag.MsgType = msgType; ViewBag.Msg = msg; } return(View("Login")); } catch (Exception ex) { throw ex; } }
public JsonResult InsUpdFoodProduct(string jsonProduct, string jsonProductDetails) { GbMProduct objProduct = null; List <KeyValuePair <string, string> > objStatus = null; List <GbMProductAttribute> listProductAttributes = null; string MsgType = "Error"; string Msg = string.Empty; try { string strDateValidation = string.Empty; objProduct = (ClsWebCommon.JsonDeserialize <GbMProduct>(jsonProduct)) as GbMProduct; DataTable dtProductAttributeDetails = GetProductAttributeTable(); if (objProduct.IsActive == "Y") { #region Food Product Detail listProductAttributes = new List <GbMProductAttribute>(); if (jsonProductDetails != "" && jsonProductDetails != null) { listProductAttributes = (ClsWebCommon.JsonDeserialize <List <GbMProductAttribute> >(jsonProductDetails)) as List <GbMProductAttribute>; } #region Get Product Attributes Datatble DataRow dr = null; foreach (GbMProductAttribute attributes in listProductAttributes) { dr = dtProductAttributeDetails.NewRow(); dr["BasePrice"] = attributes.BasePrice; dr["AttributeId1"] = attributes.AttributeId1; dr["AttributeId2"] = attributes.AttributeId2; dr["AttributeId3"] = attributes.AttributeId3; dr["AttributeId4"] = attributes.AttributeId4; dr["AttributeId5"] = attributes.AttributeId5; dr["AttributeId6"] = attributes.AttributeId6; dr["AttributeId7"] = attributes.AttributeId7; dr["AttributeId8"] = attributes.AttributeId8; dr["AttributeId9"] = attributes.AttributeId9; dr["AttributeId10"] = attributes.AttributeId10; dr["IsDefault"] = attributes.IsDefault; dr["IsActive"] = attributes.IsActive; dtProductAttributeDetails.Rows.Add(dr); } #endregion #endregion } #region Ins Upd Food Product if (strDateValidation == string.Empty) { objProduct.CrtBy = GetSession.GetSessionFromContext().UserId; objProduct.CrtIp = FSCSecurity.GetIPAddress(); string[] Out = new ClsFoodProduct().InsUpdFoodProduct(objProduct, dtProductAttributeDetails); if (Out[0] != string.Empty) { switch (Out[0]) { case CodeConstant.Code_InsertSuccess: case CodeConstant.Code_UpdateSuccess: case CodeConstant.Code_DeleteSuccess: MsgType = "Success"; Msg = HttpContext.GetGlobalResourceObject("AdminPanel", "FoodProduct_" + Out[0]).ToString(); break; case CodeConstant.Code_FOOD_ITEM_NAME_DUPLICATE: case CodeConstant.Code_FOOD_ITEM_ATTRIBUTE_MANDATORY: case CodeConstant.Code_FOOD_PRODUCT_ATTRIBUTE_NOT_EXISTS: Msg = HttpContext.GetGlobalResourceObject("AdminPanel", "FoodProduct_" + Out[0]).ToString(); break; default: Msg = HttpContext.GetGlobalResourceObject("AdminPanel", "T1100").ToString(); break; } } else { Msg = HttpContext.GetGlobalResourceObject("AdminPanel", "T1100").ToString(); } } else { Msg = strDateValidation; } #endregion objStatus = new List <KeyValuePair <string, string> >(); objStatus.Add(new KeyValuePair <string, string>("MsgType", MsgType)); objStatus.Add(new KeyValuePair <string, string>("Msg", Msg)); } catch (Exception ex) { objStatus = new List <KeyValuePair <string, string> >(); objStatus.Add(new KeyValuePair <string, string>("MsgType", MsgType)); Msg = HttpContext.GetGlobalResourceObject("AdminPanel", "T1100").ToString(); objStatus.Add(new KeyValuePair <string, string>("Msg", Msg)); throw ex; } return(Json(objStatus)); }
//Function Handles Exception and Logs to Logging Media if Logging is Enabled #region Handle Exception And Log public override void OnException(ExceptionContext filterContext) { if (filterContext.ExceptionHandled || !filterContext.HttpContext.IsCustomErrorEnabled) { return; } if (new HttpException(null, filterContext.Exception).GetHttpCode() != 500) { return; } if (!ExceptionType.IsInstanceOfType(filterContext.Exception)) { return; } FSCErrorInfo objErrorInfo = null; // if the request is AJAX return JSON else view. if (filterContext.HttpContext.Request.Headers["X-Requested-With"] == "XMLHttpRequest") { filterContext.Result = new JsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = new { error = true, message = filterContext.Exception.Message } }; } else { if (filterContext.Exception is HttpAntiForgeryException && filterContext.Exception.Message.ToLower().StartsWith("the provided anti-forgery token was meant for user \"\", but the current user is")) { var controllerName = (string)filterContext.RouteData.Values["controller"]; var actionName = (string)filterContext.RouteData.Values["action"]; var model = new FSCErrorInfo(filterContext.Exception, controllerName, actionName); model.ErrorDate = System.DateTime.Now.ToString("yyyy-mm-dd HH:mm:ss"); model.UserCode = FSCSecurity.GetUserIdentity(); model.IpAdd = FSCSecurity.GetIPAddress(); objErrorInfo = model; var isAjaxCall = string.Equals("XMLHttpRequest", filterContext.HttpContext.Request.Headers["x-requested-with"], StringComparison.OrdinalIgnoreCase); var returnUrl = !string.IsNullOrWhiteSpace(filterContext.HttpContext.Request["returnUrl"]) ? filterContext.HttpContext.Request["returnUrl"] : "/"; var response = HttpContext.Current.Response; if (isAjaxCall) { response.Clear(); response.StatusCode = 200; response.ContentType = "application/json; charset=utf-8"; response.Write(JsonConvert.SerializeObject(new { success = 1, returnUrl = returnUrl })); response.End(); } else { response.StatusCode = 200; response.Redirect(returnUrl); } } else { var controllerName = (string)filterContext.RouteData.Values["controller"]; var actionName = (string)filterContext.RouteData.Values["action"]; var model = new FSCErrorInfo(filterContext.Exception, controllerName, actionName); model.ErrorDate = System.DateTime.Now.ToString("yyyy-mm-dd HH:mm:ss"); model.UserCode = FSCSecurity.GetUserIdentity(); model.IpAdd = FSCSecurity.GetIPAddress(); objErrorInfo = model; TempDataDictionary objDataDictionary = new TempDataDictionary(); ViewDataDictionary data = filterContext.Controller.ViewData; foreach (string str in data.Keys) { objDataDictionary.Add(str, data[str]); } filterContext.Result = new ViewResult { ViewName = View, MasterName = Master, ViewData = new ViewDataDictionary <FSCErrorInfo>(model), TempData = objDataDictionary }; filterContext.ExceptionHandled = true; filterContext.HttpContext.Response.Clear(); filterContext.HttpContext.Response.StatusCode = 500; filterContext.HttpContext.Response.TrySkipIisCustomErrors = true; } } if (Convert.ToBoolean(ConfigurationManager.AppSettings["LogErrors"])) { if (objErrorInfo != null) { new FSC_ErrorLog().LogError(new ErrorLogType(), objErrorInfo.ControllerName, objErrorInfo.ActionName, objErrorInfo.Exception.GetType().FullName, objErrorInfo.Exception.Message , objErrorInfo.ErrorDate, objErrorInfo.UserCode, objErrorInfo.IpAdd); } else { new FSC_ErrorLog().LogError(new ErrorLogType(), filterContext.Controller.ToString(), filterContext.Exception.GetType().FullName, filterContext.Exception.Message , System.DateTime.Now.ToString("yyyy-mm-dd HH:mm:ss"), FSCSecurity.GetUserIdentity(), FSCSecurity.GetIPAddress()); } } }