Advertisement
Guest User

ValorPneuFormEmpresa

a guest
Nov 19th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.88 KB | None | 0 0
  1.         [Authorize(Roles = "VPQT")]
  2.         [Route("~/valorpneu/questionario/detentor/editar")]
  3.         public ActionResult ValorPneuFormEmpresa(string oldaction, int qid = 0, int pid = 33, int fid = 34, int did = 0, string companyid = "")
  4.         {
  5.             var model = new ValorPneuFormEmpresaPageObject();
  6.             if (Session["UserInfo"] != null)
  7.             {
  8.                 var userInfo = (UserInfo)Session["UserInfo"];
  9.                 var userPageInfo = new UserPageInfo();
  10.  
  11.                 if (Request.Url != null)
  12.                 {
  13.                     userInfo.UWL.BEFORE_URL = userInfo.UWL.CURRENT_URL;
  14.                     userInfo.UWL.CURRENT_URL = Request.Url.Scheme + "://" + Request.Url.Authority +
  15.                                                Request.Url.PathAndQuery;
  16.                 }
  17.                 model = Database.ValorPneuFormEmpresa("pt");
  18.                 userPageInfo.BasicCompany = userInfo.UserCompany;
  19.                 userPageInfo.BasicUser = userInfo.User;
  20.                 userPageInfo.BasicUser.CURRENT_ACTION = "ValorPneuFormEmpresa";
  21.                 userPageInfo.BasicUser.CURRENT_CONTROLLER = "ValorPneu_Questionario";
  22.                 model.PAGE_OBJECT.PAGE_INFO.ACTION = "ValorPneuFormEmpresa";
  23.                 model.PAGE_OBJECT.PAGE_INFO.CONTROLLER = "ValorPneu_Questionario";
  24.                 model.PAGE_OBJECT.UserPageInfo = userPageInfo;
  25.                 ViewBag.UserPageInfo = userPageInfo;
  26.  
  27.                 var aid = userInfo.User.ID_AGENCY;
  28.                 var cid = userInfo.User.ID_COMPANY;
  29.                 var sid = userInfo.User.ID_SBU;
  30.                 try
  31.                 {
  32.                     using (var database = new Entities())
  33.                     {
  34.                         database.Configuration.LazyLoadingEnabled = false;
  35.                         model.URL = Url.Action(oldaction, "ValorPneu_Questionario");
  36.                         model.OLDACTION = oldaction;
  37.                         model.PID = pid;
  38.                         model.FID = fid;
  39.                         model.QID = qid;
  40.                         model.hasQuest = "NO";
  41.  
  42.                         var getCities = database.valorpneu_cidade_lista.ToList();
  43.  
  44.                         if (getCities.Any())
  45.                             model.CITIES = getCities;
  46.  
  47.                         if (!string.IsNullOrEmpty(companyid))
  48.                         {
  49.                             var getCompany = database.valorpneu_detentor_e_empresa.FirstOrDefault(p => p.ID_AGENCY == aid &&
  50.                                                                                                        p.ID_COMPANY == cid &&
  51.                                                                                                        p.ID_SBU == sid &&
  52.                                                                                                        p.ID_NIF.Equals(companyid) &&
  53.                                                                                                        p.ID_DETENTOR == did &&
  54.                                                                                                        p.ID_QUESTIONARIO == qid);
  55.  
  56.                             if (getCompany != null)
  57.                             {
  58.                                 var getQuest = database.valorpneu_formulario_detentor.FirstOrDefault(
  59.                                     p => p.ID_AGENCY == aid &&
  60.                                          p.ID_COMPANY == cid &&
  61.                                          p.ID_SBU == sid &&
  62.                                          p.ID_QUESTIONARIO == qid);
  63.  
  64.                                 model.DETENTOR = getCompany;
  65.  
  66.                                 if (getCompany.RESPONDEU.Value == true)
  67.                                 {
  68.                                     model.hasQuest = "DONE";
  69.                                 }
  70.                                 else if(getQuest != null)
  71.                                 {
  72.                                     model.hasQuest = "OK";
  73.                                 }                                
  74.                             }
  75.                         }
  76.                         else
  77.                         {
  78.                             model.DETENTOR = new valorpneu_detentor_e_empresa()
  79.                             {
  80.                                 ID_NIF = "",
  81.                                 ID_DETENTOR = 0,
  82.                                 NOME_EMPRESA = string.Empty,
  83.                                 CIDADE_EMPRESA = string.Empty,
  84.                                 CONSELHO_EMPRESA = string.Empty,
  85.                                 DISTRITO_EMPRESA = string.Empty,
  86.                                 COD_POSTAL_EMPRESA = string.Empty,
  87.                                 EMAIL_EMPRESA = string.Empty,
  88.                                 TELF_EMPRESA = string.Empty,
  89.                                 MORADA_EMPRESA = string.Empty,
  90.                                 NOME_DETENTOR = string.Empty,
  91.                                 CIDADE_DETENTOR = string.Empty,
  92.                                 CONSELHO_DETENTOR = string.Empty,
  93.                                 DISTRITO_DETENTOR = string.Empty,
  94.                                 COD_POSTAL_DETENTOR = string.Empty,
  95.                                 EMAIL_DETENTOR = string.Empty,
  96.                                 TELF_DETENTOR = string.Empty,
  97.                                 MORADA_DETENTOR = string.Empty,
  98.                                 OBS = string.Empty,
  99.                                 FUNCAO = string.Empty
  100.                             };
  101.                         }
  102.                     }
  103.                 }
  104.                 catch (EndpointNotFoundException ex)
  105.                 {
  106.                     TempData["LoginError"] = "Não foi possivel fazer a ligação á base de dados.";
  107.                     return RedirectToAction("LogOff", "Account");
  108.                 }
  109.                 catch (Exception ex)
  110.                 {
  111.                     TempData["Notification"] = HtmlExtentions.Notification(HtmlExtentions.PositionType.topRight,
  112.                         HtmlExtentions.NotificationType.error,
  113.                         "Ocorreu um Erro desconhecido ao tentar ver a empresa.",
  114.                         true, "", HtmlExtentions.AnimationType.fadeInDown, HtmlExtentions.AnimationType.fadeOut,
  115.                         500, 5000, true, false, 1, true,
  116.                         HtmlExtentions.CloseType.click, "", false);
  117.                     return RedirectToAction("Index", "Home");
  118.                 }
  119.                 var breadcrumbCount = 0;
  120.                 var allNavPages = new List<PageNavigation>
  121.                 {
  122.                     UtilityExtentions.GetPageNavigation(breadcrumbCount + 1, Request.Url, "Index", "Home",
  123.                         new string[0]),
  124.                     UtilityExtentions.GetPageNavigation(breadcrumbCount + 1, Request.Url, "ValorPneuFormEmpresa",
  125.                         "ValorPneu_Questionario", new string[0], true)
  126.                 };
  127.                 //var allSideButtons = new SideBar
  128.                 //{
  129.                 //    BUTTON_GROUPS = UtilityExtentions.UpdateSideButton(userInfo.UserSideBar.BUTTON_GROUPS,
  130.                 //        "ValorPneuFormEmpresa", "ValorPneu_Questionario", new[] { "VPQT" })
  131.                 //};
  132.                 var allNavButtons = new TopMenu
  133.                 {
  134.                     TABS = UtilityExtentions.UpdateTab(userInfo.UserTopMenu.TABS, "VPQT")
  135.                 };
  136.                 model.PAGE_OBJECT.PAGE_TABS = allNavButtons;
  137.                 model.PAGE_OBJECT.PAGE_SIDEBAR = null;
  138.                 model.PAGE_OBJECT.PAGE_URLS = allNavPages;
  139.                 Session["UserInfo"] = userInfo; //update session
  140.             }
  141.             else
  142.             {
  143.                 TempData["LoginError"] = "A sua sessão foi terminada ou expirou.";
  144.                 return RedirectToAction("Index", "Account");
  145.             }
  146.             return View("ValorPneuFormEmpresa", model);
  147.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement