示例#1
0
        public ActionResult Display(long Id)
        {
            ViewBag.Title = "مشاهده تیکت";
            Dictionary <string, string> parameter = new Dictionary <string, string>();

            parameter.Add("TicketId", Id.ToString());
            List <TicketContent> tk = new TicketContent().GetAll(parameter);

            ViewBag.Id = Id;
            return(View(tk));
        }
示例#2
0
        public ActionResult Display(string ticketId, string message)
        {
            string permissions = "";
            int    stat        = 0;

            if (HasPermission("[ticket]", ref permissions, ref stat))
            {
                return(RedirectToAction("AccessDeny"));
            }
            ViewBag.permissions = permissions;
            ViewBag.stat        = stat;
            ViewBag.Title       = "مشاهده تیکت";
            try
            {
                Ticket tk = new Ticket();
                tk.Id         = long.Parse(ticketId);
                tk            = tk.GetOne();
                tk.Status     = 2;
                tk.StatusDate = DateTime.Now;
                tk.Update();

                TicketContent tkc = new TicketContent();
                tkc.Content      = message;
                tkc.UserId       = int.Parse(Session["user_id"].ToString());
                tkc.RegisterDate = DateTime.Now;
                tkc.TicketId     = tk.Id;
                tkc.Add();

                return(RedirectToAction("Index", "Ticket"));
            }
            catch (Exception ex)
            {
                ErrorLog log = new ErrorLog();
                log.Description = ex.Message;
                if (ex.InnerException != null)
                {
                    log.Description += ";" + ex.Message;
                }
                log.ErrorDate = DateTime.Now;
                log.Add();
            }
            Dictionary <string, string> parameter = new Dictionary <string, string>();

            parameter.Add("TicketId", ticketId);
            List <TicketContent> model = new TicketContent().GetAll(parameter);

            ViewBag.Id = ticketId;
            return(View(model));
        }
示例#3
0
        public ActionResult Display(long Id)
        {
            string permissions = "";
            int    stat        = 0;

            if (HasPermission("[ticket]", ref permissions, ref stat))
            {
                return(RedirectToAction("AccessDeny"));
            }
            ViewBag.permissions = permissions;
            ViewBag.stat        = stat;
            ViewBag.Title       = "مشاهده تیکت";
            Dictionary <string, string> parameter = new Dictionary <string, string>();

            parameter.Add("TicketId", Id.ToString());
            List <TicketContent> tk = new TicketContent().GetAll(parameter);

            ViewBag.Id = Id;
            return(View(tk));
        }
示例#4
0
        public ActionResult New(string subject, string message, string periority)
        {
            ViewBag.Title = "ارسال تیکت جدید";
            Ticket tk = new Ticket();

            try
            {
                tk.CreateDate = DateTime.Now;
                tk.CustomerId = long.Parse(Session["customer_id"].ToString());
                tk.Priority   = int.Parse(periority);
                tk.Status     = 1;
                tk.StatusDate = DateTime.Now;
                tk.Subject    = subject;
                tk.Add();

                TicketContent tkc = new TicketContent();
                tkc.Content      = message;
                tkc.CustomerId   = long.Parse(Session["customer_id"].ToString());
                tkc.RegisterDate = DateTime.Now;
                tkc.TicketId     = tk.Id;
                tkc.Add();

                return(RedirectToAction("Index", "Ticket"));
            }
            catch (Exception ex)
            {
                ErrorLog log = new ErrorLog();
                log.Description = ex.Message;
                if (ex.InnerException != null)
                {
                    log.Description += ";" + ex.Message;
                }
                log.ErrorDate = DateTime.Now;
                log.Add();
            }
            return(View(tk));
        }
        public async Task <IActionResult> AddTicket(string userId, [FromForm] TicketForCreateDto ticketForCreateDto)
        {
            var ticketFromRepo = await _db.TicketRepository
                                 .GetAsync(p => p.Title == ticketForCreateDto.Title && p.UserId == userId);

            if (ticketFromRepo == null)
            {
                var ticket = new Ticket()
                {
                    UserId      = userId,
                    Closed      = false,
                    IsAdminSide = false
                };

                _mapper.Map(ticketForCreateDto, ticket);

                await _db.TicketRepository.InsertAsync(ticket);

                if (await _db.SaveAsync())
                {
                    var ticketContent = new TicketContent()
                    {
                        TicketId    = ticket.Id,
                        IsAdminSide = false,
                        Text        = ticketForCreateDto.Text
                    };
                    if (ticketForCreateDto.File != null)
                    {
                        if (ticketForCreateDto.File.Length > 0)
                        {
                            var uploadRes = await _uploadService.UploadFileToLocal(
                                ticketForCreateDto.File,
                                userId,
                                _env.WebRootPath,
                                $"{Request.Scheme ?? ""}://{Request.Host.Value ?? ""}{Request.PathBase.Value ?? ""}",
                                "Files\\TicketContent"
                                );

                            if (uploadRes.Status)
                            {
                                ticketContent.FileUrl = uploadRes.Url;
                            }
                            else
                            {
                                _db.TicketRepository.Delete(ticket.Id);
                                await _db.SaveAsync();

                                return(BadRequest(uploadRes.Message));
                            }
                        }
                        else
                        {
                            ticketContent.FileUrl = "";
                        }
                    }
                    else
                    {
                        ticketContent.FileUrl = "";
                    }

                    await _db.TicketContentRepository.InsertAsync(ticketContent);

                    if (await _db.SaveAsync())
                    {
                        return(CreatedAtRoute("GetTicket", new { v = HttpContext.GetRequestedApiVersion().ToString(), id = ticket.Id, userId = userId },
                                              ticket));
                    }
                    else
                    {
                        _db.TicketRepository.Delete(ticket.Id);
                        await _db.SaveAsync();

                        return(BadRequest("خطا در ثبت اطلاعات "));
                    }
                }
                else
                {
                    return(BadRequest("خطا در ثبت اطلاعات "));
                }
            }
            {
                return(BadRequest("این تیکت قبلا ثبت شده است"));
            }
        }
        public async Task <IActionResult> AddTicketContent(string id, string userId, [FromForm] TicketContentForCreateDto ticketContentForCreateDto)
        {
            var ticketFromRepo = (await _db.TicketRepository.GetByIdAsync(id));

            if (ticketFromRepo != null)
            {
                ticketFromRepo.DateModified = DateTime.Now;
                ticketFromRepo.IsAdminSide  = false;
                _db.TicketRepository.Update(ticketFromRepo);
                await _db.SaveAsync();
            }
            var ticketContent = new TicketContent()
            {
                TicketId    = id,
                IsAdminSide = false,
                Text        = ticketContentForCreateDto.Text
            };

            if (ticketContentForCreateDto.File != null)
            {
                if (ticketContentForCreateDto.File.Length > 0)
                {
                    var uploadRes = await _uploadService.UploadFileToLocal(
                        ticketContentForCreateDto.File,
                        userId,
                        _env.WebRootPath,
                        $"{Request.Scheme ?? ""}://{Request.Host.Value ?? ""}{Request.PathBase.Value ?? ""}",
                        "Files\\TicketContent"
                        );

                    if (uploadRes.Status)
                    {
                        ticketContent.FileUrl = uploadRes.Url;
                    }
                    else
                    {
                        return(BadRequest(uploadRes.Message));
                    }
                }
                else
                {
                    ticketContent.FileUrl = "";
                }
            }
            else
            {
                ticketContent.FileUrl = "";
            }


            await _db.TicketContentRepository.InsertAsync(ticketContent);

            if (await _db.SaveAsync())
            {
                return(CreatedAtRoute("GetTicketContent", new { v = HttpContext.GetRequestedApiVersion().ToString(), userId = userId, ticketId = id, id = ticketContent.Id, },
                                      ticketContent));
            }
            else
            {
                return(BadRequest("خطا در ثبت اطلاعات "));
            }
        }