protected void Application_PostAuthenticateRequest(Object sender, EventArgs e) { var authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value); if (authTicket != null && !authTicket.Expired) { var roles = authTicket.UserData.Split(','); HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(new FormsIdentity(authTicket), roles); CurrentUserName = authTicket.Name; CurrentUserID = (roles != null && roles.Length > 0) ? CommonSafeConvert.ToInt(roles[0]) : 0; } else { CurrentUserName = ""; CurrentUserID = 0; } } else { CurrentUserName = ""; CurrentUserID = 0; } }
private ShopChangeStatus ValidateAndChangeShop(int shopId) { try { var currentUserId = CommonSafeConvert.ToInt(Session["CurrentUserID"]); var changeShopRequestobject = new ShopChangeRequest(); changeShopRequestobject.ShopId = shopId; changeShopRequestobject.Userid = currentUserId; var response = new CommonAjaxCallToWebAPI().AjaxPost("/api/common/ValidateAndChangeShop", changeShopRequestobject, Convert.ToString(Session["BSWebApiToken"])).Result; if (response.IsSuccessStatusCode) { var rslt = response.Content.ReadAsStringAsync().Result; var shopChangeStatus = new JavaScriptSerializer().Deserialize <ShopChangeStatus>(rslt); return(shopChangeStatus); } else { return(null); } } catch { return(null); } }
public BSEntityFramework_ResultType InsertProducts(AddProductViewModel newProduct) { try { BSEntityFramework_ResultType result; using (BSDBEntities EF = new BSDBEntities()) { using (var transaction = EF.Database.BeginTransaction()) { try { var shopId = newProduct.ProductDetails.ShopID; var totalProducts = EF.TBL_Products.Count(x => x.ShopID == shopId) + 1; newProduct.ProductDetails.ProductID = CommonSafeConvert.ToInt(Convert.ToString(shopId) + Convert.ToString(totalProducts)); newProduct.ProductDetails.TBL_ProductImages = newProduct.ProductImages; EF.TBL_Products.Add(newProduct.ProductDetails); EF.SaveChanges(); //var resultChild = InsertProductImages(newProduct.ProductImages, // newProduct.ProductDetails.ProductID); //if (resultChild.Result != BSResult.Success) //{ // return resultChild; //} transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); var logact = new LoggerActivity(); result = new BSEntityFramework_ResultType(BSResult.Fail, newProduct, null, "Technical issue"); logact.ErrorSetup("WebApp", "InsertShope Failed", "", "", "", ex.Message); return(result); } } result = new BSEntityFramework_ResultType(BSResult.Success, newProduct.ProductDetails, null, "Created Sucessfully"); return(result); } } catch (DbEntityValidationException dbValidationEx) { return(FormatException(dbValidationEx, newProduct.ProductDetails)); } catch (Exception ex) { var logact = new LoggerActivity(); var result = new BSEntityFramework_ResultType(BSResult.Fail, newProduct.ProductDetails, null, "Technical issue"); logact.ErrorSetup("WebApp", "Insert Products Failed", "", "", "", ex.Message); return(result); } }
public ActionResult ChangeShop(string id) { var shopId = CommonSafeConvert.ToInt(id); if (shopId > 0) { var shopChangeStatus = ValidateAndChangeShop(shopId); ViewBag.ShopChangeStatus = shopChangeStatus; Session["menuData"] = CommonSafeConvert.GetMenuString(shopChangeStatus.MenuList); Session["CurrentShopID"] = shopId; } else { ViewBag.ShopChangeStatus = new ShopChangeStatus() { IsSuccess = false, Message = "Invalid Shop. Please logoff and login again." }; } return(RedirectToAction("Index", "Home")); }
public JsonResult <ShopChangeStatus> ValidateAndChangeShop(ShopChangeRequest scr) { var validShopId = CommonSafeConvert.ToInt(scr.ShopId); if (validShopId > 0) { Home_Activity homeActivity = new Home_Activity(); Plugins_Activity pluginActivity = new Plugins_Activity(); if (homeActivity.IsValidShopForUser(scr.Userid, validShopId)) { var menuList = pluginActivity.GetPluginMenuDetailList(scr.Userid, validShopId); return (Json <ShopChangeStatus>( new ShopChangeStatus() { IsSuccess = true, Message = "Shop change successfully", MenuList = menuList })); } return(Json <ShopChangeStatus>( new ShopChangeStatus() { IsSuccess = false, Message = "Invalid Shop. Please logoff and login again.", MenuList = null })); } else { var result = new ShopChangeStatus { IsSuccess = false, Message = "Invalid Shop. Please logoff and login again.", MenuList = null }; return(Json <ShopChangeStatus>(result)); } }
public BSEntityFramework_ResultType InsertShopOffer(AddShopOffersViewModel newShopOffer) { try { using (BSDBEntities EF = new BSDBEntities()) { var shopId = newShopOffer.ShopOffer.ShopID; var totalOffers = EF.TBL_ShopOffers.Count(x => x.ShopID == shopId) + 1; newShopOffer.ShopOffer.OfferID = CommonSafeConvert.ToInt(Convert.ToString(shopId) + Convert.ToString(totalOffers)); foreach (var prod in newShopOffer.OfferonProducts) { prod.CreatedBy = newShopOffer.ShopOffer.CreatedBy; prod.CreateDate = DateTime.Now; prod.IsActive = true; } newShopOffer.ShopOffer.TBL_OfferOnProducts = (newShopOffer.OfferonProducts); EF.TBL_ShopOffers.Add(newShopOffer.ShopOffer); EF.SaveChanges(); } var result = new BSEntityFramework_ResultType(BSResult.Success, newShopOffer.ShopOffer, null, "Created Sucessfully"); return(result); } catch (DbEntityValidationException dbValidationEx) { return(FormatException(dbValidationEx, newShopOffer)); } catch (Exception ex) { var logact = new LoggerActivity(); var result = new BSEntityFramework_ResultType(BSResult.Fail, newShopOffer, null, "Technical issue"); logact.ErrorSetup("WebApp", "InsertShopOffer Failed", "", "", "", ex.Message); return(result); } }
public ActionResult AddShop(AddShopViewModel model) { try { var currentUserId = CommonSafeConvert.ToInt(Session["CurrentUserID"]); if (!LoginResult.VerifyUserId(currentUserId)) { } if (ModelState.IsValid) { model.ShopDetails.CreatedBy = currentUserId; model.ShopPostalDetails.CreatedBy = currentUserId; model.ShopPostalDetails.IsActive = true; var response = new CommonAjaxCallToWebAPI().AjaxPost("/api/shop/PostNewShopes", model, Convert.ToString(Session["BSWebApiToken"])).Result; if (response.IsSuccessStatusCode) { var rslt = response.Content.ReadAsStringAsync().Result; return(Json(new JavaScriptSerializer().Deserialize <object>(rslt), JsonRequestBehavior.AllowGet)); } else { return(null); } } FillViewDatasForAddShop(); return(View("AddShop", model)); } catch { FillViewDatasForAddShop(); return(View()); } }
public async Task <ActionResult> AddShopOffer(AddShopOffersViewModel model) { try { if (ModelState.IsValid) { using (var client = new HttpClient()) { var currentUserId = CommonSafeConvert.ToInt(Session["CurrentUserID"]); model.ShopOffer.ShopID = GetCurrentShopId(); model.ShopOffer.CreatedBy = currentUserId; var selectedProductList = new JavaScriptSerializer().Deserialize <List <SelectedProductList> >(model.SelectedProductJson); model.OfferonProducts = new List <TBL_OfferOnProducts>(); selectedProductList.ForEach(x => model.OfferonProducts.Add(new TBL_OfferOnProducts() { ProductID = x.ProductID, OfferID = model.ShopOffer.OfferID })); client.BaseAddress = new Uri(WebAppConfig.GetConfigValue("WebAPIUrl")); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); var response = await client.PostAsJsonAsync("/api/shopoffers/PostNewShopOffers", model); // var response = new CommonAjaxCallToWebAPI().AjaxPost(@"/api/shopoffers/PostNewShopOffers", model); if (response.StatusCode == System.Net.HttpStatusCode.OK) { var rslt = await response.Content.ReadAsStringAsync(); var reslt = new JavaScriptSerializer().Deserialize <BSEntityFramework_ResultType>(rslt); if (reslt.Result == BSResult.FailForValidation) { foreach (var valerr in reslt.EntityValidationException) { ModelState.AddModelError("BS Errors", valerr); } } else { ModelState.AddModelError("BS Errors", reslt.ResultMsg); } //return reslt; FillViewDatasForAddShopOffers(); return(View()); } else { FillViewDatasForAddShopOffers(); return(View()); } } } FillViewDatasForAddShopOffers(); return(View("AddShopOffer", model)); } catch (Exception ex) { FillViewDatasForAddShopOffers(); return(View()); } }
public async Task <ActionResult> EditOffer(ProductUpdateForm formDATA) { var ProductDetails = new JavaScriptSerializer().Deserialize <TBL_Products>(formDATA.ProductDetails); UserDetails currentUser = GetCurrentUserDetails(); AddProductViewModel model = new AddProductViewModel(); model.ProductDetails = ProductDetails; if (formDATA.file != null) { model.ProductImages = new List <TBL_ProductImages>(); model.ProductImages.Add(new TBL_ProductImages() { ImageID = CommonSafeConvert.ToInt(formDATA.imgId), ProductID = ProductDetails.ProductID, UpdatedBy = currentUser.UserId, UpdateDate = DateTime.Now, IsActive = true, ProductImage = CommonSafeConvert.ConvertToBytesFromFile(formDATA.file) }); } if (ModelState.IsValid) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(WebAppConfig.GetConfigValue("WebAPIUrl")); // Add an Accept header for JSON format. client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); var response = new CommonAjaxCallToWebAPI().AjaxPost("/api/product/PostEditProduct", model, Convert.ToString(Session["BSWebApiToken"])).Result; // var response = await client.PostAsJsonAsync("/api/product/PostEditProduct", model); if (response.StatusCode == System.Net.HttpStatusCode.OK) { var rslt = await response.Content.ReadAsStringAsync(); var reslt = new JavaScriptSerializer().Deserialize <BSEntityFramework_ResultType>(rslt); if (reslt.Result == BSResult.FailForValidation) { foreach (var valerr in reslt.EntityValidationException) { ModelState.AddModelError("BS Errors", valerr); } } //return reslt; //FillViewDatasForAddShop(); var allErrors = ModelState.Values.SelectMany(v => v.Errors); return(Json(allErrors, JsonRequestBehavior.AllowGet)); } else { return(Json("Failed", JsonRequestBehavior.AllowGet)); } } } return(Json(new { Valid = ModelState.IsValid, UserID = currentUser.UserId, //Errors = GetErrorsFromModelState(), Status = "Validation Failed" })); }
public JsonResult <object> GetProductListView(int shopId, string sortColumnName, string sortOrder, int pageSize, int currentPage, string prodName = "", string brandName = "", string barCode = "", string productType = "", string isAvailable = "true", string availableQty = "", string isActive = "true", string prodCategory = "", string prodSubType = "", string prodMrp = "", string prodShopPrice = "" ) { var BSResult = ProductsActivity.GetProductListView(shopId, sortColumnName, sortOrder, pageSize, currentPage, prodName, brandName, barCode, CommonSafeConvert.ToInt(productType), Convert.ToBoolean(isAvailable), availableQty, Convert.ToBoolean(isActive), CommonSafeConvert.ToInt(prodCategory), CommonSafeConvert.ToInt(prodSubType), CommonSafeConvert.ToDecimal(prodMrp), CommonSafeConvert.ToDecimal(prodShopPrice) ); return(Json <object>(BSResult.Entity)); // return Json<object>(obj); }