Example #1
0
        public ActionResult CreateTicket(string name, string email, string phonenumber, string companyname, string pilihTiket,
                                         string TicketSubject, string description, string pilihPriority, string pilihEscalatedto)
        {
            var ticket = TicketNo.Create(User.Identity.Name, "TICKET");

            Ticketing tick = Ticketing.Create(User.Identity.Name, phonenumber);

            Ticket   objTicket = tick.TicketObject;
            Customer cust      = tick.CustObject;

            cust.FirstName     = name;
            cust.Email         = email;
            cust.CompanyName   = companyname;
            objTicket.Priority = pilihPriority;
            if (pilihEscalatedto == "-")
            {
                objTicket.Escalation = User.Identity.Name;
            }
            else
            {
                objTicket.Escalation = pilihEscalatedto;
            }
            objTicket.TicketDescription = description;
            objTicket.TicketSubject     = TicketSubject;
            objTicket.TicketOwner       = User.Identity.Name;
            objTicket.CreatedBy         = User.Identity.Name;
            objTicket.CreatedDate       = DateTime.Now;
            objTicket.UpdatedBy         = User.Identity.Name;
            objTicket.UpdatedDate       = DateTime.Now;

            tick.Update();
            ViewBag.SuccessMsg = "Success";
            return(View());
        }
Example #2
0
        public ActionResult Index(ViewModel.Ticket m)
        {
            string errorMessage = string.Empty;

            try
            {
                foreach (var item in m.Solution)
                {
                    if (item.UpdateDate == DateTime.MinValue)
                    {
                        item.UpdateDate = DateTime.Now;
                    }
                }

                using (DatabaseManager ctx = new DatabaseManager(true))
                {
                    if (string.IsNullOrEmpty(m.TicketNo))
                    {
                        m.TicketNo = TicketNo.Create(User.Identity.Name, "TICKET");
                    }

                    Ticket obj = ViewModel.Ticket.ConvertToTicketBusiness(m);
                    obj.Requester    = m.Requester.Email;
                    obj.TicketStatus = TicketStatus.Open.ToString();
                    obj.Escalation   = User.Identity.Name;
                    obj.CreatedBy    = User.Identity.Name;
                    obj.CreatedDate  = DateTime.Now;
                    obj.UpdatedBy    = obj.CreatedBy;
                    obj.UpdatedDate  = obj.CreatedDate;

                    string updatecommand = "Created";//GetUpdateCommand(m, obj);
                    var    objHistory    = SaveTicketHistory(obj, updatecommand);

                    if (m.isClosed)
                    {
                        obj.TicketStatus        = TicketStatus.Closed.ToString();
                        objHistory.TicketStatus = TicketStatus.Closed.ToString();
                    }

                    if (obj.IsValid && objHistory.IsValid)
                    {
                        obj        = obj.Save();
                        objHistory = objHistory.Save();
                    }
                    else
                    {
                        System.Text.StringBuilder sb = new System.Text.StringBuilder();
                        foreach (var item in obj.GetBrokenRules())
                        {
                            sb.AppendLine(item.Description);
                        }

                        foreach (var item in objHistory.GetBrokenRules())
                        {
                            sb.AppendLine(item.Description);
                        }
                        errorMessage = sb.ToString();
                    }

                    Customer cust = ViewModel.Ticket.ConvertToCustomerBusiness(m.Requester);

                    if (string.IsNullOrEmpty(cust.CreatedBy))
                    {
                        cust.CreatedBy   = User.Identity.Name;
                        cust.CreatedDate = DateTime.Now;
                    }

                    cust.UpdatedBy   = User.Identity.Name;
                    cust.UpdatedDate = DateTime.Now;

                    if (cust.IsValid)
                    {
                        cust = cust.Save();
                    }
                    else
                    {
                        System.Text.StringBuilder sb = new System.Text.StringBuilder();
                        foreach (var item in cust.GetBrokenRules())
                        {
                            sb.AppendLine(item.Description);
                        }
                        errorMessage = errorMessage + "---" + sb.ToString();
                    }

                    if (string.IsNullOrEmpty(errorMessage))
                    {
                        ctx.SaveChanges();
                        ViewBag.SuccessMsg = "Success";
                    }
                    else
                    {
                        throw new Exception("Terjadi kesalahan!");
                    }
                }
            }
            catch (Exception ex)
            {
                errorMessage     = ex.Message + "---" + errorMessage;
                ViewBag.ErrorMsg = errorMessage;

                LogActivity log = LogActivity.NewLogActivity();
                log.ControllerName = "Ticketing";
                log.ActionName     = "Index";
                log.LogData        = Newtonsoft.Json.JsonConvert.SerializeObject(errorMessage);
                log.CreatedBy      = User.Identity.Name;
                log.CreatedDate    = DateTime.Now;
                log = log.Save();
                return(View(m));
            }

            return(RedirectToAction("IndexInbox", "Inbox"));
        }