protected void Page_Load(object sender, EventArgs e) { string ResponseValue = ""; string ResponseString = ""; try { if (CookieProxy.Instance().HasKey("t")) { UserProfile UserProfileObj = new UserProfile(); Category CategoryObj = new Category(); UserProfileObj.SetToken(CookieProxy.Instance().GetValue("t").ToString()); CategoryObj.SetCategoryId(int.Parse(Request.Form["c"])); APIResponse Response = new CategoryBusinessLayerTemplate(UserProfileObj).Delete(CategoryObj); ResponseValue = Response.ToString(); if (Response == APIResponse.NOT_OK) { ResponseString = "Unable to delete the category, please check logs"; } else { Logger.Instance().Log(Info.Instance(), new LogInfo(new AdminUserTemplate().FetchParticularProfile(UserProfileObj).GetEmail() + " deleted the category ID " + Request.Form["c"].ToString())); } } else { ResponseValue = APIResponse.NOT_OK.ToString(); ResponseString = "NOT_AUTHENTICATED"; } } catch (NullReferenceException nex) { CookieProxy.Instance().SetValue("LoginMessage", "Not Authorized, please login with correct credentials. If you believe this is an error, please check logs".ToString(), DateTime.Now.AddDays(2)); Logger.Instance().Log(Warn.Instance(), nex); ResponseValue = APIResponse.NOT_OK.ToString(); ResponseString = "NOT_AUTHENTICATED"; } catch (MySqlException mse) { Logger.Instance().Log(Warn.Instance(), mse); ResponseValue = APIResponse.NOT_OK.ToString(); ResponseString = "Unable to delete category, please delete the products first linked to category before deleting category"; } catch (Exception ex) { Logger.Instance().Log(Warn.Instance(), ex); ResponseValue = APIResponse.NOT_OK.ToString(); ResponseString = "Unable to delete the category, please check logs"; } finally { var output = new { Code = ResponseValue, Response = ResponseString, }; Response.Write(new JavaScriptSerializer().Serialize(output)); } }
protected void Page_Load(object sender, EventArgs e) { string ResponseValue = ""; string ResponseString = ""; List <ICategory> Categories = null; try { UserProfile UserProfileObj = new UserProfile(); UserProfileObj.SetToken(CookieProxy.Instance().GetValue("t").ToString()); Categories = new CategoryBusinessLayerTemplate(UserProfileObj).Select(); if (null == Categories) { ResponseValue = APIResponse.NOT_OK.ToString(); ResponseString = "NOT_AUTHENTICATED"; CookieProxy.Instance().SetValue("LoginMessage", "Not Authorized, please login with correct credentials".ToString(), DateTime.Now.AddDays(2)); Logger.Instance().Log(Info.Instance(), new LogInfo(new AdminUserTemplate().FetchParticularProfile(UserProfileObj).GetEmail() + " fetched category list")); } else { Logger.Instance().Log(Info.Instance(), new LogInfo(new AdminUserTemplate().FetchParticularProfile(UserProfileObj).GetEmail() + " fetched category list ")); ResponseValue = APIResponse.OK.ToString(); ResponseString = "SUCCESS"; } } catch (NullReferenceException nex) { CookieProxy.Instance().SetValue("LoginMessage", "Not Authorized, please login with correct credentials. If you believe this is an error, please check logs".ToString(), DateTime.Now.AddDays(2)); Logger.Instance().Log(Warn.Instance(), nex); ResponseValue = APIResponse.NOT_OK.ToString(); ResponseString = "NOT_AUTHENTICATED"; } catch (Exception ex) { Logger.Instance().Log(Warn.Instance(), ex); ResponseValue = APIResponse.NOT_OK.ToString(); ResponseString = "Unable to fetch the list of categories, please check logs"; } finally { var output = new { Code = ResponseValue, Response = ResponseString, CategoriesList = Categories }; Response.Write(new JavaScriptSerializer().Serialize(output)); } }