Пример #1
0
        public ActionResult Details(AssistantAddResponseViewModel modelAssistant)
        {
            AssistantAddResponseViewModel tmp = modelAssistant;
            var userid  = User.Identity.GetUserId();
            var tihid   = tmp.AssistantDetailsTickets.FirstOrDefault().TiH_ID;
            int counter = db.TicketHeaderAssistants.Where(x => x.TiA_TiHID == tihid && x.TiA_AsSID == userid).Count();

            if (counter == 0) //blokada przed próbą odpowiedzi ze strony niepodppiętych asystentów
            {
                TempData["Error"] = "Nie masz udzielić odpowiedzi na zgłoszenie, ponieważ nie jesteś do niego przypisany!";
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                db.TicketPositions.Add(new TicketPosition
                {
                    TiP_Date = DateTime.Now,
                    TiP_LP   = (from m in tmp.AssistantDetailsTickets
                                orderby m.TiP_LP descending
                                select m.TiP_LP).FirstOrDefault() + 1,
                    TiP_TiHID   = tmp.AssistantDetailsTickets.FirstOrDefault().TiH_ID,
                    TiP_ASSID   = User.Identity.GetUserId(),
                    TiP_Content = tmp.NewPositionContent
                });
                db.SaveChanges();

                return(RedirectToAction("Details", new { id = tmp.AssistantDetailsTickets.FirstOrDefault().TiH_ID }));
            }
            ViewBag.Id      = tihid;
            ViewBag.Subject = db.TicketHeaders.Where(x => x.TiH_ID == tihid).FirstOrDefault().TiH_Subject;
            return(View("DetailsAssistants", tmp));
        }
Пример #2
0
        public ActionResult Details(int?id)
        {
            var userid = User.Identity.GetUserId();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ViewBag.Id      = id;
            ViewBag.Subject = db.TicketHeaders.Where(x => x.TiH_ID == id).FirstOrDefault().TiH_Subject;
            if (User.IsInRole("Customer"))
            {
                if (db.TicketHeaders.Where(x => x.TiH_ID == id).FirstOrDefault().TiH_CMPID != db.Customers.Where(y => y.Id == userid).FirstOrDefault().CuS_CMPID) //blokada przed próbą podejrzenia  ze strony "innych" klientów
                {
                    TempData["Error"] = "Nie masz uprawnień do przeglądania wybranego zgłoszenia.";
                    return(RedirectToAction("List"));
                }
                var model = (from tih in db.TicketHeaders
                             join tip in db.TicketPositions on tih.TiH_ID equals tip.TiP_TiHID
                             join ass in db.Assistants on tip.TiP_ASSID equals ass.Id into _ass
                             from ass in _ass.DefaultIfEmpty()
                             join cus in db.Customers on tip.TiP_CUSID equals cus.Id into _cus
                             from cus in _cus.DefaultIfEmpty()
                             join tis in db.TicketStates on tih.TiH_TiSID equals tis.TiS_ID
                             where tih.TiH_ID == id
                             select new CustomerDetailsTicketViewModel
                {
                    TiH_ID = tih.TiH_ID,
                    TiP_LP = tip.TiP_LP,
                    TiP_Date = tip.TiP_Date,
                    AssOrCus = (ass.Id == null && cus.Id != null) ? 1 :
                               (ass.Id != null && cus.Id == null) ? 2 : -1,
                    TiP_Content = tip.TiP_Content,
                    OperatorName = (ass.Id == null && cus.Id != null) ? cus.CuS_Name + " " + cus.CuS_Surname :
                                   (ass.Id != null && cus.Id == null) ? ass.AsS_Name + " " + ass.AsS_Surname : "Error",
                }).ToList();

                var model2 = new CustomerAddResponseViewModel()
                {
                    CustomerDetailsTickets = model
                };


                return(View("DetailsCustomers", model2));
            }
            else
            {
                var model = (from tih in db.TicketHeaders
                             join tip in db.TicketPositions on tih.TiH_ID equals tip.TiP_TiHID
                             join ass in db.Assistants on tip.TiP_ASSID equals ass.Id into _ass
                             from ass in _ass.DefaultIfEmpty()
                             join cus in db.Customers on tip.TiP_CUSID equals cus.Id into _cus
                             from cus in _cus.DefaultIfEmpty()
                             join tis in db.TicketStates on tih.TiH_TiSID equals tis.TiS_ID
                             where tih.TiH_ID == id
                             select new AssistantDetailsTicketViewModel
                {
                    TiH_ID = tih.TiH_ID,
                    TiP_LP = tip.TiP_LP,
                    TiP_Date = tip.TiP_Date,
                    AssOrCus = (ass.Id == null && cus.Id != null) ? 1 :
                               (ass.Id != null && cus.Id == null) ? 2 : -1,
                    TiP_Content = tip.TiP_Content,
                    OperatorName = (ass.Id == null && cus.Id != null) ? cus.CuS_Name + " " + cus.CuS_Surname :
                                   (ass.Id != null && cus.Id == null) ? ass.AsS_Name + " " + ass.AsS_Surname : "Error",
                }).ToList();
                var model2 = new AssistantAddResponseViewModel()
                {
                    AssistantDetailsTickets = model,
                    TicketWorkLog           = new TicketWorkLog
                    {
                        TwL_ASSID     = userid,
                        TwL_TIHID     = id,
                        TwL_StartDate = DateTime.Now,
                        TwL_EndDate   = DateTime.Now
                    }
                };
                return(View("DetailsAssistants", model2));
            }
        }