Exemple #1
0
        public IActionResult Upload(IFormFile filedata, string id)
        {
            var item = _ticket.GetById(Guid.Parse(id));

            if (item == null)
            {
                return(NotFound());
            }

            var _uploadDir = "uploads/travel";
            var upload     = Path.Combine(_env.WebRootPath, _uploadDir);

            if (!Directory.Exists(upload))
            {
                Directory.CreateDirectory(upload);
            }

            if (filedata.Length > 0)
            {
                var prefix   = Guid.NewGuid().ToString("n") + "_";
                var filepath = Path.Combine(upload, prefix + filedata.FileName);
                var imageSrc = $"{_uploadDir}/{prefix}{filedata.FileName}";
                using (var filestream = new FileStream(filepath, FileMode.Create))
                {
                    filedata.CopyTo(filestream);
                }

                var result = new Attachment()
                {
                    Name     = filedata.FileName,
                    FileType = _fileHelper.GetMimeTypeByName(filedata.FileName),
                    Type     = Attachment.FILE_TYPE_UPLOAD,
                    Path     = imageSrc,
                    Size     = filedata.Length / 1024
                };


                if (!string.IsNullOrEmpty(item.Files))
                {
                    var CurrentFiles = JsonConvert.DeserializeObject <List <string> >(item.Files);
                    CurrentFiles.Add(result.Path);
                    item.Files = JsonConvert.SerializeObject(CurrentFiles);
                    _ticket.Update(item);
                }
                else
                {
                    var list = new List <string>();
                    list.Add(result.Path);
                    item.Files = JsonConvert.SerializeObject(list);
                    _ticket.Update(item);
                }
                return(Json(new
                {
                    data = result
                }));
            }

            return(Json(new BadRequestResult()));
        }
Exemple #2
0
        public IActionResult Booking(Guid id, TicketInfoFormModel model)
        {
            if (ModelState.IsValid)
            {
                var Ticket = _ticket.GetAll().Where(x => x.ClaimId.Equals(id)).FirstOrDefault();
                Ticket.Note        = model.Description;
                Ticket.Price       = model.Price;
                Ticket.Description = model.Description;
                Ticket.Status      = model.Status;
                _ticket.Update(Ticket);

                // Send Notif To Contractor if ticket exists
                if (!string.IsNullOrEmpty(Ticket.Files))
                {
                    var Travel         = Service.GetById(Ticket.ClaimId);
                    var Contractor     = _userHelper.GetUserProfile(Travel.ContractorId.Value);
                    var UserContractor = _userHelper.GetUser(Contractor.ApplicationUserId);
                    if (UserContractor != null)
                    {
                        var callbackUrl = Url.Action("Index",
                                                     "Travel",
                                                     new { area = "Admin" },
                                                     _hostConfiguration.Protocol,
                                                     _hostConfiguration.Name);


                        _notif.Send(
                            User,                                          // User From
                            "Booked Ticket",                               // Subject
                            Contractor.Name,                               // User target name
                            UserContractor.Email,                          // User target email
                            callbackUrl,                                   // Link CallBack
                            " Your Ticket is issued as for below Thanks ", // Email content or descriptions
                            model.Description,                             // Description
                            NotificationInboxStatus.Request,               // Notif Status
                            Activities.Travel,                             // Activity Status,
                            Ticket.Files
                            );
                    }
                }


                TempData["success"] = "OK";
                return(RedirectToAction("Booking", new { id = id }));
            }
            return(NotFound());
        }