private void ShowShortParameterForm(ReportParametersModel model, Report report, ParamObj data, IQueryable <Permission> permissions) { var user = Session[Strings.USER].Cast <UserDetail>(); var repository = Session.Get <TagRepository>(Strings.TagRepository, new TagRepository()); var ctx1 = PTFContext.Current; var ctx2 = PTFReportsContext.Current; // retailers var list = CommonTools.Cached <List <Branch> >(string.Concat(user.Ud_loginName, "_List<Branch>"), () => new List <Branch>()); if (list.Count == 0) { repository.Clear(); foreach (Permission p in permissions) { var branch = ctx1.Branches.FirstOrDefault( br => br.br_iso_id == p.IsoID && br.br_ho_id == p.HoID && br.br_id == p.RetailerID); list.Add(branch); repository.SetTag(branch); } } //get user's retailer if (list.Count == 0) { var branch = Branch.GetUserDefault(user); list.Add(branch); repository.SetTag(branch); } ViewData[ParamMapping.RetailerID.ToString()] = new MultiSelectList(list.OrderBy(br => br.FullName2), "br_id", "FullName2", null); }
public JsonResult ReportParameters(ParamObj data) { ViewData[Strings.ERR] = "No report selected"; ReportParametersModel model = null; if (Session[Strings.REPORTID] == null || data == null) { return(Json("err", JsonRequestBehavior.AllowGet)); } var currenReportId = Session[Strings.REPORTID].Cast <Guid>(); var user = Session[Strings.USER].Cast <UserDetail>(); model = Session.Get <ReportParametersModel>(Strings.CachedMODELParameters, new ReportParametersModel()); model.CurrentStep = data.Step; if (model.CurrentStep == "Reset") { model = new ReportParametersModel(); } var ctx1 = PTFContext.Current; var ctx2 = PTFReportsContext.Current; var report = ctx2.Reports.First(r => r.ReportID == currenReportId); if (report == null) { Session.Remove(Strings.REPORTID); Session.Remove(Strings.CachedMODELParameters); var result1 = this.RenderPartialToString("ReportParameters", model); return(Json(result1, JsonRequestBehavior.AllowGet)); } else { model.Name = report.Name; model.Description = report.Description; model.Page = report.Page; model.ReportID = report.ReportID; model.CountryID = user.Ud_iso_id; model.CompanyID = user.Ud_ho_id; model.LanguageID = user.Ud_languageId.GetValueOrDefault((int)eLanguage.English); } var permissions = CommonTools.Cached <IQueryable <Permission> >(string.Concat(user.Ud_loginName, "_Permissions"), () => ctx2.Permissions.Where(p => p.UserID == user.Ud_id && p.IsoID == user.Ud_iso_id)); var companies = permissions.GroupBy(c => c.HoID); string result2; if (companies.Count() <= 1) { ShowShortParameterForm(model, report, data, permissions); result2 = this.RenderPartialToString("ReportParametersShort", model); } else { ShowLongParameterForm(model, report, data); result2 = this.RenderPartialToString("ReportParameters", model); } return(Json(result2, JsonRequestBehavior.AllowGet)); }
private void ShowLongParameterForm(ReportParametersModel model, Report report, ParamObj data) { var user = Session[Strings.USER].Cast <UserDetail>(); var repository = Session.Get <TagRepository>(Strings.TagRepository, new TagRepository()); var ctx1 = PTFContext.Current; var ctx2 = PTFReportsContext.Current; if (model.CurrentStep == "IsoID") { model.CurrentStep = "CompanyID"; } else if (model.CurrentStep == "CompanyID") { model.CurrentStep = "RetailerID"; } else if (model.CurrentStep == "RetailerID") { model.CurrentStep = "FormSubmit"; } else if (model.CurrentStep == "FormSubmit") { model.CurrentStep = null; } switch (model.CurrentStep) { case "": case null: { goto case "IsoID"; } case "IsoID": { model.CurrentStep = "IsoID"; model.SkipCountry = true; model.CountryID = user.Ud_iso_id; goto case "CompanyID"; //always get user country var list = new List <ISO_ptf>(); list.Add(ISO_ptf.GetUserDefault(user)); ViewData[ParamMapping.IsoID.ToString()] = new SelectList(list.OrderBy(c => c.iso_country), "iso_number", "iso_country", null); } break; case "CompanyID": { model.CurrentStep = "CompanyID"; model.CompanyID = user.Ud_ho_id; model.Country = ISO_ptf.GetNameByID(model.CountryID); var list = new List <HeadOffice>(); //user permissions var permissions = ctx2.Permissions.Where(p => p.UserID == user.Ud_id && p.IsoID == model.CountryID); foreach (var gp in permissions.GroupBy(c => c.HoID)) { var p = gp.First(); list.Add(ctx1.HeadOffices.FirstOrDefault( ho => ho.ho_iso_id == p.IsoID && ho.ho_id == p.HoID)); } model.SkipCompany = list.Count < 2; //get user's company if (list.Count == 0) { model.CompanyID = user.Ud_ho_id; goto case "RetailerID"; } ViewData[ParamMapping.CompanyID.ToString()] = new SelectList(list.OrderBy(ho => ho.ho_name), "ho_id", "ho_name", null); } break; case "RetailerID": { model.CurrentStep = "RetailerID"; model.CompanyID = data.CompanyID.Parse(user.Ud_ho_id); model.Company = HeadOffice.GetNameByID(user.Ud_iso_id, model.CompanyID); // retailers var list = new List <Branch>(); //user permissions var permissions = ctx2.Permissions.Where(p => p.UserID == user.Ud_id && p.IsoID == user.Ud_iso_id && p.HoID == model.CompanyID); repository.Clear(); foreach (Permission p in permissions) { var branch = ctx1.Branches.FirstOrDefault( br => br.br_iso_id == p.IsoID && br.br_ho_id == p.HoID && br.br_id == p.RetailerID); list.Add(branch); repository.SetTag(branch); } //get user's retailer if (list.Count == 0) { var branch = Branch.GetUserDefault(user); list.Add(branch); repository.SetTag(branch); } ViewData[ParamMapping.RetailerID.ToString()] = new MultiSelectList(list.OrderBy(br => br.FullName2), "br_id", "FullName2", null); } break; } }