public void ProcessRequest(HttpContext context) { if (context.Session["Key"] == null) throw new Exception("Ошибка обновления"); int? ShopId = null; try { ShopId = Convert.ToInt32(context.Session["ShopId"].ToString()); } catch { } int? UserId = null; try { UserId = Convert.ToInt32(context.Session["UserId"].ToString()); } catch { } var dsLogin = new DataSets.dsLogin(); (new DataSets.dsLoginTableAdapters.taShops()).Fill(dsLogin.tbShops); (new DataSets.dsLoginTableAdapters.taUsers()).Fill(dsLogin.tbUsers); var JObject = new JObject(); var JShops = new JArray(); foreach (dsLogin.tbShopsRow rw in dsLogin.tbShops.Select("", "[Название] ASC")) { var rwc = dsLogin.tbUsers.Select( String.Format("[Код магазина]={0:G}", rw.Код), "[ФИО] ASC"); if (rwc.Length <= 0) continue; if (rw.Код == ShopId) JObject.Add(new JProperty("Выбранный_магазин", ShopId)); var JUsers = new JArray(); foreach (dsLogin.tbUsersRow rwu in rwc) { if (rw.Код == ShopId && rwu.Код == UserId) JObject.Add(new JProperty("Выбранный_сотрудник", UserId)); JUsers.Add(new JObject( new JProperty("Код", rwu.Код), new JProperty("ФИО", rwu.ФИО))); } JShops.Add(new JObject( new JProperty("Название", rw.Название), new JProperty("Код", rw.Код), new JProperty("Сотрудники",JUsers))); } JObject.Add(new JProperty("Магазины", JShops)); context.Response.ContentType = "application/json"; context.Response.Write(JObject.ToString()); }
public void ProcessRequest(HttpContext context) { if (context.Session["Key"] == null) throw new Exception("Ошибка обновления"); int? UserId = null; try { UserId = Convert.ToInt32(context.Request["UserId"].ToString()); } catch { } int? ShopId = null; try { ShopId = Convert.ToInt32(context.Request["ShopId"].ToString()); } catch { } if (UserId == null || ShopId == null) return; string Password = ""; try { Password = context.Request["Password"].ToString(); } catch { } int? CurrentUserId = null; try { CurrentUserId = Convert.ToInt32(context.Session["UserId"].ToString()); } catch { } var JObject = new JObject(); if (UserId < 0 || UserId > 0 && UserId == CurrentUserId || LocalDBService.CheckPassword((int)UserId, Password)) { context.Session.Add("UserId", (int)UserId); context.Session.Add("ShopId", (int)ShopId); context.Session.Add("Authentication", true); var dsLogin = new DataSets.dsLogin(); (new DataSets.dsLoginTableAdapters.taShops()).Fill(dsLogin.tbShops); (new DataSets.dsLoginTableAdapters.taUsers()).Fill(dsLogin.tbUsers); if (UserId > 0) { var rwUser = (dsLogin.tbUsersRow) (dsLogin.tbUsers.Select(String.Format("[Код]={0}", UserId))[0]); context.Session.Add("UserName", rwUser.ФИО); } else { context.Session.Add("UserName", "Покупатель #" + (-(int)UserId).ToString()); } var rwShop = (dsLogin.tbShopsRow) (dsLogin.tbShops.Select(String.Format("[Код]={0}", ShopId))[0]); context.Session.Add("ShopName", rwShop.Название); context.Session.Add("ReceiptNumber", LocalDBService.FirstReceiptNumber((int)UserId, (int)ShopId)); JObject.Add(new JProperty("hasSuccess", true)); JObject.Add(new JProperty("message", "Аутентификация прошла успешно")); } else { JObject.Add(new JProperty("hasSuccess", false)); JObject.Add(new JProperty("message", "Вы ввели неправильный пароль")); } context.Response.ContentType = "application/json"; context.Response.Write(JObject.ToString()); }