public async Task <ResponseDto <string> > CreateTicket(TicketVM model, IFormFileCollection attachments, ApplicationUser applicationUser)
        {
            var ticketDto = mapper.Map <TicketDto>(model);

            if (applicationUser != null)
            {
                ticketDto.u_customer_email = applicationUser.Email;
                ticketDto.u_customer_name  = applicationUser.FullName;
                ticketDto.u_id             = applicationUser.IdentityNumber;
                ticketDto.u_mobile         = "+966" + applicationUser.PhoneNumber.Substring(1);
            }

            HttpClient client        = CreateHttpClient();
            var        stringPayload = JsonConvert.SerializeObject(ticketDto);
            var        httpContent   = new StringContent(stringPayload, Encoding.UTF8, "application/json");

            var responseTask = await client.PostAsync($"/api/sn_customerservice/csmtetcoapi/sn_customerservice_case", httpContent);

            if (responseTask.IsSuccessStatusCode)
            {
                var readTask = await responseTask.Content.ReadAsStringAsync();

                var serviceNowResult = JsonConvert.DeserializeObject <InsertTicketResponseDto>(readTask);

                if (serviceNowResult.result.Status.ToLower() == "failure")
                {
                    return new ResponseDto <string> {
                               StatusCode = StatusCode.SaveFailed
                    }
                }
                ;

                var photoFile = attachments.Count > 0 ? attachments[0] : null;
                if (photoFile != null)
                {
                    byte[] imageByte = null;

                    BinaryReader rdr = new BinaryReader(photoFile.OpenReadStream());
                    imageByte       = rdr.ReadBytes((int)photoFile.Length);
                    model.PhotoFile = imageByte;
                    var fileUploaded = UploadTicketAttachment(photoFile.FileName, model.PhotoFile, serviceNowResult.result.Response.sys_id);
                    if (!fileUploaded)
                    {
                        return new ResponseDto <string> {
                                   StatusCode = StatusCode.SaveFailed
                        }
                    }
                    ;
                }
                return(new ResponseDto <string> {
                    StatusCode = StatusCode.OK, Data = serviceNowResult.result.Response.Number
                });
            }
            else
            {
                return(new ResponseDto <string> {
                    StatusCode = StatusCode.SaveFailed
                });
            }
        }
 public void Update(int id, TicketVM ticketVM)
 {
     this.Id          = id;
     this.From_Userid = ticketVM.From_UserId;
     this.Message     = ticketVM.Message;
     this.UpdateDate  = DateTimeOffset.Now.ToLocalTime();
 }
        public CommonResponse <TicketVM> DeleteData(TicketVM data, TableTransactionVM transaction)
        {
            CommonResponse <TicketVM> result;

            using Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction dbTransaction = DbContext.Database.BeginTransaction();

            try
            {
                string transactionId = TransactionRepository.InitializeTransaction(transaction);

                result = TicketRepository.DeleteData(data, transactionId);

                dbTransaction.Commit();
            }
            catch (Exception e)
            {
                Logger.LogError("Error Deleting Ticket Data by IP Address {0} : {1}\nInner Ex : {2}",
                                transaction?.IpAddress ?? "",
                                e.Message ?? "",
                                e.InnerException?.Message ?? ""
                                );

                result = new CommonResponse <TicketVM>
                {
                    Status  = false,
                    Code    = "E-003",
                    Message = "Delete Data Failed! Please Contact an Web Administrator!",
                    Data    = new TicketVM[] { data },
                };
            }

            return(result);
        }
Exemple #4
0
        public async Task <IActionResult> SellTicket(TicketVM ticket)
        {
            if (ModelState.IsValid)
            {
                if (_unitOfWork.Routes.Get(ticket.RouteId) != null)
                {
                    var entity = new Ticket
                    {
                        RouteiD  = ticket.RouteId,
                        ClientId = ticket.Client,
                        SaleDate = System.DateTime.Now
                    };

                    _unitOfWork.Tickets.Create(entity);
                    _unitOfWork.Save();

                    var currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

                    var history = new TicketHistory
                    {
                        TicketId   = entity.Id,
                        EmployeeId = currentUser.Id
                    };

                    _unitOfWork.TicketHistories.Create(history);
                    _unitOfWork.Save();

                    return(RedirectToAction("ViewTickets"));
                }
            }
            return(View(ticket));
        }
        public IActionResult Upsert(int?id)
        {
            TicketVM ticketVM = new TicketVM()
            {
                Ticket      = new Ticket(),
                ProductList = _unitOfWork.Product.GetAll().Select(i => new SelectListItem
                {
                    Text  = i.Title,
                    Value = i.Id.ToString()
                })
            };

            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);
            var user           = _unitOfWork.ApplicationUser.GetFirstOrDefault(i => i.Id == claim.Value);

            ticketVM.Ticket.Email = user.Email;
            _unitOfWork.Save();

            if (id == null)
            {
                //this is for create
                return(View(ticketVM));
            }
            if (ticketVM.Ticket == null)
            {
                return(NotFound());
            }
            return(View(ticketVM));
        }
Exemple #6
0
        public async Task <GenericResponse> RaiseTicket(TicketVM model)
        {
            GenericResponse res = null;

            try
            {
                string _requestType   = Enum.GetName(typeof(RequestType), Convert.ToInt32(model.requestType));
                string _priorityLevel = Enum.GetName(typeof(PriorityLevel), Convert.ToInt32(model.priorityLevel));
                model.ticket.requestType   = _requestType;
                model.ticket.priorityLevel = _priorityLevel;
                var         endpoint    = _configuration.GetSection("API").GetSection("raiseticket").Value;
                HttpClient  client      = _apiHelper.InitializeClient();
                var         json        = JsonConvert.SerializeObject(model.ticket);
                HttpContent raiseTicket = new StringContent(json, Encoding.UTF8, "application/json");
                var         response    = await client.PostAsync(endpoint, raiseTicket);

                if (response.IsSuccessStatusCode)
                {
                    res = JsonConvert.DeserializeObject <GenericResponse>(await response.Content.ReadAsStringAsync());
                }
                else
                {
                    res = JsonConvert.DeserializeObject <GenericResponse>(await response.Content.ReadAsStringAsync());
                }
            }
            catch (Exception ex)
            {
                _logger.LogInformation($"{ex?.InnerException?.InnerException?.Message}");
            }
            return(res);
        }
Exemple #7
0
        public bool Insert(TicketVM ticketVM)
        {
            var push             = new Ticket(ticketVM);
            var getStatus        = applicationContext.Statuses.Find(ticketVM.Status_Id);
            var getProjectMember = applicationContext.ProjectMembers.Find(ticketVM.FromMember_Id);
            var getProject       = applicationContext.Projects.Find(ticketVM.Project_Id);

            if (getStatus != null && getProjectMember != null && getProject != null)
            {
                push.Status        = getStatus;
                push.ProjectMember = getProjectMember;
                push.Project       = getProject;
                applicationContext.Tickets.Add(push);
                var result = applicationContext.SaveChanges();
                if (result > 0)
                {
                    status = true;
                    return(status);
                }
                else
                {
                    return(status);
                }
            }
            else
            {
                return(status);
            }
        }
Exemple #8
0
 public TicketView()
 {
     this.InitializeComponent();
     ViewModel = new TicketVM();
     ListContainer.ItemsSource = ViewModel.Tickets;
     this.Loaded += OnLoaded;
 }
        public IActionResult Upsert(TicketVM ticketVM)
        {
            if (ModelState.IsValid)
            {
                _unitOfWork.Ticket.Add(ticketVM.Ticket);
                ticketVM.Ticket.CreatedDate  = DateTime.Now;
                ticketVM.Ticket.TicketStatus = "1";
                ticketVM.Ticket.Status       = "Pending";
                _unitOfWork.Save();

                EmailTemplate emailTemplate = _db.EmailTemplates.Where(e => e.Id == Convert.ToInt32(EnEmailTemplate.TicketGenerate)).FirstOrDefault();
                var           appuser       = _db.Tickets.FirstOrDefault(u => u.Email == ticketVM.Ticket.Email);
                var           user          = _unitOfWork.ApplicationUser.GetFirstOrDefault(i => i.Email == appuser.Email);
                emailTemplate.Content = emailTemplate.Content.Replace("###Name###", user.Name);
                _emailSender.SendEmailAsync(ticketVM.Ticket.Email, emailTemplate.Subject, emailTemplate.Content);

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                ticketVM.ProductList = _unitOfWork.Product.GetAll().Select(i => new SelectListItem
                {
                    Text  = i.Title,
                    Value = i.Id.ToString()
                });
                if (ticketVM.Ticket.Id != 0)
                {
                    ticketVM.Ticket = _unitOfWork.Ticket.Get(ticketVM.Ticket.Id);
                }
            }
            return(View(ticketVM));
        }
Exemple #10
0
        // GET: Tickets/Create
        public ActionResult Create()
        {
            var ticketVM = new TicketVM();

            ViewBag.KundenList = db.Kunden;
            return(PartialView("Create", ticketVM));
        }
Exemple #11
0
        public TicketVM GetOneData(string id)
        {
            TicketVM data = TicketServices.GetDataById(id);

            data.SetLoggedUser(User.FindFirst(ClaimTypes.Name)?.Value ?? "");

            return(data);
        }
 public ActionResult <ResponseVM> UpdateTicket([FromBody] TicketVM ticketVM)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest("Something went wrong"));
     }
     return(ticketService.Update(ticketVM));
 }
        public IHttpActionResult Delete(TicketVM ticket, int id)
        {
            var del = myContext.Ticket.Find(id);

            myContext.Ticket.Remove(del);
            myContext.SaveChanges();

            return(Ok(del));
        }
Exemple #14
0
        /// <summary>
        /// 编辑
        /// </summary>
        /// <returns></returns>
        public ActionResult Edit(TicketVM vm)
        {
            vm.Ticket = _TicketService.GetById(vm.Id) ?? new Ticket();
            //获取餐厅列表
            int tcount = 0;

            vm.BusinessList = _businessService.GetListByType((int)BusinessTypeEnum.景点, 1, 1000, out tcount);

            return(View(vm));
        }
        public IHttpActionResult Put(TicketVM ticket, int id)
        {
            var put = myContext.Ticket.Find(id);

            put.subject = ticket.subject;
            myContext.Entry(put).State = EntityState.Modified;
            myContext.SaveChanges();

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #16
0
        // PUT: api/Tickets/5

        public HttpResponseMessage PutUpdateTicket(int id, TicketVM ticketVM)
        {
            var message = Request.CreateErrorResponse(HttpStatusCode.NotModified, "Not Modified");
            var result  = _iTicketService.Update(id, ticketVM);

            if (result)
            {
                message = Request.CreateResponse(HttpStatusCode.OK, ticketVM);
            }
            return(message);
        }
Exemple #17
0
 public bool Update(int id, TicketVM ticketVM)
 {
     if (string.IsNullOrWhiteSpace(ticketVM.Id.ToString()) && string.IsNullOrWhiteSpace(ticketVM.Status_Id.ToString()))
     {
         return(status);
     }
     else
     {
         return(_iTicketRepository.Update(id, ticketVM));
     }
 }
Exemple #18
0
 public bool Insert(TicketVM ticketVM)
 {
     if (string.IsNullOrWhiteSpace(ticketVM.Status_Id.ToString()) && string.IsNullOrWhiteSpace(ticketVM.FromMember_Id.ToString()) && string.IsNullOrWhiteSpace(ticketVM.Project_Id.ToString()))
     {
         return(status);
     }
     else
     {
         return(_iTicketRepository.Insert(ticketVM));
     }
 }
Exemple #19
0
        // POST: api/Tickets
        public HttpResponseMessage InsertTicket(TicketVM ticketVM)
        {
            var message = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Bad Request");
            var result  = _iTicketService.Insert(ticketVM);

            if (result)
            {
                message = Request.CreateResponse(HttpStatusCode.OK, ticketVM);
            }
            return(message);
        }
 public bool Insert(TicketVM ticketVM)
 {
     if (string.IsNullOrWhiteSpace(ticketVM.Message))
     {
         return(status);
     }
     else
     {
         return(iTicketRepository.Insert(ticketVM));
     }
 }
Exemple #21
0
        public CommonResponse <TicketVM> DeleteData([FromBody] TicketVM data)
        {
            string myUserId = User.FindFirst(ClaimTypes.Name)?.Value;

            TableTransactionVM transaction = new TableTransactionVM
            {
                IpAddress = HttpContext.Connection.RemoteIpAddress.ToString(),
                UserId    = myUserId,
            };

            return(TicketServices.DeleteData(data, transaction));
        }
Exemple #22
0
        public static Ticket ConvertTicketVMToTicket(TicketVM ticketVM)
        {
            var ticket = new Ticket();

            ticket.Erstellung   = DateTime.Now;
            ticket.Beschreibung = ticketVM.Beschreibung;
            ticket.Kategorie    = ticketVM.Kategorie;
            ticket.KundeID      = ticketVM.KundeID;
            ticket.Software     = ticketVM.Software;
            ticket.Status       = ticketVM.Status;
            ticket.Zustaendig   = ticketVM.Zustaendig;

            return(ticket);
        }
Exemple #23
0
        public ActionResult GetTickets(ForCreateForms param, InformAboutPassengers personsInf, int[] HaveBed, int[] HaveTea)
        {
            int             countTickets = personsInf.FirstName.Count();
            string          startStation = statServ.GetFirstStationOnRoute(param.TrainNumber);
            List <TicketVM> tickets      = new List <TicketVM>();

            for (int i = 0; i < countTickets; i++)
            {
                TicketVM ticket = new TicketVM();
                ticket.TrainNumber       = param.TrainNumber;
                ticket.CarriageType      = carrServ.GetCarrTypeByCarrOrderInTrain(param.TrainNumber, param.CarriageOrder);
                ticket.CarriageOrder     = param.CarriageOrder;
                ticket.SeatNumber        = personsInf.SeatNumber[i];
                ticket.StartStation      = param.BeginInputStation;
                ticket.EndStation        = param.EndInputStation;
                ticket.DepartureDateTime = sqlServ.GetDepartArrivlDateTime(param.DepartDateTime, param.TrainNumber, startStation, param.BeginInputStation);
                ticket.ArrivalDateTime   = sqlServ.GetDepartArrivlDateTime(param.DepartDateTime, param.TrainNumber, startStation, param.EndInputStation);
                ticket.FirstName         = personsInf.FirstName[i];
                ticket.LastName          = personsInf.LastName[i];
                ticket.BirthDate         = personsInf.BirthDate[i];
                ticket.PersonType        = personsInf.PersonType[i];
                if (HaveTea != null && HaveTea.Count() != 0 && HaveTea.Contains(personsInf.SeatNumber[i]))
                {
                    ticket.HaveTea = true;
                }
                if (HaveBed != null && HaveBed.Count() != 0 && HaveBed.Contains(personsInf.SeatNumber[i]))
                {
                    ticket.HaveBed = true;
                }
                tickets.Add(ticket);
            }

            mapper.CreateNewTickets(ref tickets, personsInf);

            List <string> filesPaths = WorkWithPDFAndEmail.CreatePdfFileAndSendEmail(tickets, personsInf);

            string ticketsPDFfilePath = WorkWithPDFAndEmail.MergePDFFiles(filesPaths);
            int    idx = ticketsPDFfilePath.LastIndexOf('\\');

            FilePdfTickets file = new FilePdfTickets(ticketsPDFfilePath.Substring(0, idx), ticketsPDFfilePath.Substring(idx + 1));

            return(View("GetTickets", file));
        }
Exemple #24
0
        public ActionResult Create(TicketVM ticketVM)
        {
            if (ModelState.IsValid)
            {
                var tiket = Helper.ConvertTicketVMToTicket(ticketVM);
                db.Tickets.Add(tiket);

                try
                {
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    TempData["messageError"] = string.Format("Fehler! " + ex.Message);
                    return(View("Index"));
                }
            }
            return(null);
        }
        public bool Insert(TicketVM ticketVM)
        {
            var push        = new Ticket(ticketVM);
            var getEmployee = myContext.Employees.Find(ticketVM.From_UserId);

            push.Employee = getEmployee;
            myContext.Tickets.Add(push);
            var result = myContext.SaveChanges();

            if (result > 0)
            {
                status = true;
            }
            else
            {
                return(status);
            }
            return(status);
        }
Exemple #26
0
        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="pn">分页下标</param>
        /// <returns></returns>
        public ActionResult List(TicketVM vm, int pn = 1)
        {
            int total     = 0,
                pageIndex = pn,
                pageSize  = PagingConfig.PAGE_SIZE;
            //分页查询
            var list   = _TicketService.GetManagerList(vm.QueryName, vm.QueryBusinessmanName, pageIndex, pageSize, out total, int.Parse(Loginer.BusinessId));
            var paging = new Paging <Ticket>()
            {
                Items = list,
                Size  = PagingConfig.PAGE_SIZE,
                Total = total,
                Index = pn,
            };

            vm.Paging = paging;

            return(View(vm));
        }
        public JsonResult Detail(int id)
        {
            TicketVM ticket       = null;
            var      responseTask = Client.GetAsync("Ticket/" + id.ToString());

            responseTask.Wait();
            var result = responseTask.Result;

            if (result.IsSuccessStatusCode)
            {
                var readTask = result.Content.ReadAsAsync <TicketVM>();
                readTask.Wait();
                ticket = readTask.Result;
            }
            else
            {
                ModelState.AddModelError(string.Empty, "404 Not Found");
            }
            return(Json(new { data = ticket }, JsonRequestBehavior.AllowGet));
        }
Exemple #28
0
        public bool Update(int id, TicketVM ticketVM)
        {
            var pull             = Get(id);
            var getStatus        = applicationContext.Statuses.Find(ticketVM.Status_Id);
            var getProjectMember = applicationContext.ProjectMembers.Find(ticketVM.FromMember_Id);
            var getProject       = applicationContext.Projects.Find(ticketVM.Project_Id);

            if (getStatus != null && getProjectMember != null && getProject != null)
            {
                pull.Status        = getStatus;
                pull.ProjectMember = getProjectMember;
                pull.Project       = getProject;
                pull.Update(id, ticketVM);
                var result = applicationContext.SaveChanges();
                if (result > 0)
                {
                    status = true;
                    return(status);
                }
                else
                {
                    return(status);
                }
            }
            else
            {
                return(status);
            }
            //var get = Get(id);
            //if (get != null)
            //{
            //    get.Update(id, ticketVM);
            //    applicationContext.Entry(get).State = EntityState.Modified;
            //    applicationContext.SaveChanges();
            //    return true;
            //}
            //else
            //{
            //    return false;
            //}
        }
Exemple #29
0
        public async Task <IActionResult> RaiseTicket()
        {
            TicketVM ticketVM      = new TicketVM();
            bool     _checkSession = CheckSession();

            if (_checkSession)
            {
                return(RedirectToAction(nameof(Logout)));
            }
            try
            {
                var getClients = await _client.GetAllClients();

                ticketVM.clients = getClients;
            }
            catch (Exception ex)
            {
                _logger.LogError($"{ex?.InnerException?.InnerException?.Message}");
            }
            return(View(ticketVM));
        }
Exemple #30
0
        public async Task <IActionResult> RaiseTicket(TicketVM model)
        {
            bool _checkSession = CheckSession();

            if (_checkSession)
            {
                return(RedirectToAction(nameof(Logout)));
            }
            try
            {
                if (ModelState.IsValid)
                {
                    var result = await _ticket.RaiseTicket(model);

                    if (result != null)
                    {
                        _logger.LogInformation($"ticket raised successfully....");
                        TempData["msg"] = $"Ticket created successfully";
                    }
                    else
                    {
                        _logger.LogInformation($"could not raise ticket....");
                    }
                }
                else
                {
                    _logger.LogInformation($"Invalid model state....", model.clients);
                    ViewBag.msg = $"Please fill out all fields";
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"{ex?.InnerException?.InnerException?.Message}");
            }
            return(RedirectToAction(nameof(Index)));
        }