Example #1
0
 public bool Create(Ticket ticket)
 {
     _ticketDbContext.Tickets.Add(ticket);
     try
     {
         _ticketDbContext.SaveChanges();
     }
     catch (Exception)
     {
         return(false);
     }
     return(true);
 }
Example #2
0
 public bool Create(User user)
 {
     _ticketDbContext.Users.Add(user);
     try
     {
         _ticketDbContext.SaveChanges();
     }
     catch (Exception)
     {
         return(false);
     }
     return(true);
 }
        public ActionResult EditUser(string id, EditUserViewModel collection, string Roles)
        {
            try
            {
                using (TicketDbContext context = TicketDbContext.Create())
                {
                    var user = UserManager.FindById(id);

                    if (Roles == "0")
                    {
                        var collec = UserManager.GetRoles(user.Id);
                        RemoveRolesFromUser(user, collec);
                        UserManager.AddToRole(user.Id, "Helper");
                    }
                    else if (Roles == "1")
                    {
                        var collec = UserManager.GetRoles(user.Id);
                        RemoveRolesFromUser(user, collec);
                        UserManager.AddToRole(user.Id, "User");
                    }
                    else
                    {
                        var collec = UserManager.GetRoles(user.Id);
                        RemoveRolesFromUser(user, collec);
                        UserManager.AddToRole(user.Id, "Admin");
                    }
                    context.SaveChanges();
                }
                return(RedirectToAction("ManageUser"));
            }
            catch
            {
                return(View());
            }
        }
        public string DeleteTicket(int Id)
        {
            try
            {
                if (Id == 0)
                {
                    return("Deletation not succeded");
                }
                var ticket = _context.Set <Ticket>().Find(Id);

                _context.Set <Ticket>().Remove(ticket);
                _context.SaveChanges();
                return("Deletation succeded");
            }
            catch (Exception exception)
            {
                return(exception.Message);
            }
        }
Example #5
0
        public ContentResult AddComment(string userComment, string ticketId, string userId)
        {
            Console.WriteLine("usercomment " + userComment);
            Console.WriteLine("ticketid " + ticketId);
            Console.WriteLine("userid " + userId);


            string response = $"AddComment() Error!!! Name: {userComment} Input is either null or empty!";



            if (!String.IsNullOrEmpty(userComment))
            {
                int ticketIdParsed;
                try
                {
                    ticketIdParsed = Int32.Parse(ticketId);

                    ApplicationUser NewApplicationUser = context.Users.Find(userId);
                    Ticket          NewTicket          = context.Tickets.Find(ticketIdParsed);

                    Comment comment = new Comment
                    {
                        UserComment = userComment,
                        Ticket      = NewTicket,
                        User        = NewApplicationUser,
                        CommentDate = DateTime.Now,
                    };
                    Console.WriteLine("comment.UserComment: " + comment.UserComment);
                    Console.WriteLine("comment.TicketId) " + comment.TicketId);
                    Console.WriteLine("comment.UserId " + comment.UserId);
                    Console.WriteLine("comment.CommentDate " + comment.CommentDate);
                    context.Comments.Add(comment);
                    context.SaveChanges();
                }
                catch (FormatException)
                {
                    response = ($"DeleteCategory() Error!!! Product Id: '{ticketId}' could not be parsed!");
                }
                response = userComment;
            }
            return(Content(response));
        }
        public ActionResult Register(RegisterRequest request)
        {
            if (ModelState.IsValid)
            {
                User user = new User
                {
                    Password        = request.Password,
                    ConfirmPassword = request.ConfirmPassword,
                    Email           = request.Email,
                    FirstName       = request.FirstName,
                    LastName        = request.LastName,
                };


                TicketDbContext.Users.Add(user);
                TicketDbContext.SaveChanges();
            }
            return(View());
        }
        public ActionResult EditUserAdvande(string id, EditUserViewModel collection, string Roles)
        {
            try
            {
                using (TicketDbContext context = TicketDbContext.Create())
                {
                    var user = context.Users.FirstOrDefault(x => x.Id == id);

                    if (Roles == "0")
                    {
                        var collec = UserManager.GetRoles(user.Id);
                        RemoveRolesFromUser(user, collec);
                        UserManager.AddToRole(user.Id, "Helper");
                    }
                    else if (Roles == "1")
                    {
                        var collec = UserManager.GetRoles(user.Id);
                        RemoveRolesFromUser(user, collec);
                        UserManager.AddToRole(user.Id, "User");
                    }
                    else
                    {
                        var collec = UserManager.GetRoles(user.Id);
                        RemoveRolesFromUser(user, collec);
                        UserManager.AddToRole(user.Id, "Admin");
                    }
                    user.TypeOfTicket = collection.TypeOfTicket;

                    context.SaveChanges();
                }
                return(RedirectToAction("ManageUser"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Add(TicketViewModel ticketForm)
        {
            if (!ModelState.IsValid)
            {
                return(View(ticketForm));
            }

            var userId     = User.Identity.GetUserId();
            var ticketToDb = new Ticket
            {
                UserId         = userId,
                Title          = ticketForm.Title,
                Description    = ticketForm.Description,
                TypeOfTicket   = ticketForm.TypeOfTicket,
                StatusOfTicket = StatusesOfTicket.Zalozony,
                CreationTime   = DateTime.Now,
            };

            _context.Tickets.Add(ticketToDb);
            _context.SaveChanges();

            ModelState.Clear();
            return(View(new TicketViewModel(true)));
        }
        public async Task <IActionResult> ProcessAddTicketAsync(AddTicketViewModel addTicketViewModel)
        {
            if (ModelState.IsValid)
            {
                //if you want to add files to server use below code

                /*string uniqueFileName1 = null;
                 * string uniqueFileName2 = null;
                 * string uniqueFileName3 = null;
                 *
                 * if (addTicketViewModel.Photo1 != null)
                 * {
                 *  // The image must be uploaded to the images folder in wwwroot
                 *  // To get the path of the wwwroot folder we are using the inject
                 *  // HostingEnvironment service provided by ASP.NET Core
                 *  string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images");
                 *  // To make sure the file name is unique we are appending a new
                 *  // GUID value and and an underscore to the file name
                 *  uniqueFileName1 = Guid.NewGuid().ToString() + "_" + addTicketViewModel.Photo1.FileName;
                 *  string filePath = Path.Combine(uploadsFolder, uniqueFileName1);
                 *  // Use CopyTo() method provided by IFormFile interface to
                 *  // copy the file to wwwroot/images folder
                 *  addTicketViewModel.Photo1.CopyTo(new FileStream(filePath, FileMode.Create));
                 * }
                 * if (addTicketViewModel.Photo2 != null)
                 * {
                 *  // The image must be uploaded to the images folder in wwwroot
                 *  // To get the path of the wwwroot folder we are using the inject
                 *  // HostingEnvironment service provided by ASP.NET Core
                 *  string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images");
                 *  // To make sure the file name is unique we are appending a new
                 *  // GUID value and and an underscore to the file name
                 *  uniqueFileName2 = Guid.NewGuid().ToString() + "_" + addTicketViewModel.Photo2.FileName;
                 *  string filePath = Path.Combine(uploadsFolder, uniqueFileName2);
                 *  // Use CopyTo() method provided by IFormFile interface to
                 *  // copy the file to wwwroot/images folder
                 *  addTicketViewModel.Photo2.CopyTo(new FileStream(filePath, FileMode.Create));
                 * }
                 * if (addTicketViewModel.Photo3 != null)
                 * {
                 *  // The image must be uploaded to the images folder in wwwroot
                 *  // To get the path of the wwwroot folder we are using the inject
                 *  // HostingEnvironment service provided by ASP.NET Core
                 *  string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images");
                 *  // To make sure the file name is unique we are appending a new
                 *  // GUID value and and an underscore to the file name
                 *  uniqueFileName3 = Guid.NewGuid().ToString() + "_" + addTicketViewModel.Photo3.FileName;
                 *  string filePath = Path.Combine(uploadsFolder, uniqueFileName3);
                 *  // Use CopyTo() method provided by IFormFile interface to
                 *  // copy the file to wwwroot/images folder
                 *  addTicketViewModel.Photo3.CopyTo(new FileStream(filePath, FileMode.Create));
                 * }*/

                //adds uploaded files to database
                if (Request.Form.Files.Count == 1)
                {
                    IFormFile file = Request.Form.Files.FirstOrDefault();
                    using (var dataStream = new MemoryStream())
                    {
                        await file.CopyToAsync(dataStream);

                        addTicketViewModel.Picture1 = dataStream.ToArray();
                    }
                }
                else if (Request.Form.Files.Count == 2)
                {
                    IFormFile[] file = new IFormFile[2];
                    file[0] = Request.Form.Files[0];
                    using (var dataStream1 = new MemoryStream())
                    {
                        await file[0].CopyToAsync(dataStream1);
                        addTicketViewModel.Picture1 = dataStream1.ToArray();
                    }
                    file[1] = Request.Form.Files[1];
                    using (var dataStream2 = new MemoryStream())
                    {
                        await file[1].CopyToAsync(dataStream2);
                        addTicketViewModel.Picture2 = dataStream2.ToArray();
                    }
                }
                else if (Request.Form.Files.Count == 3)
                {
                    IFormFile[] file = new IFormFile[3];
                    file[0] = Request.Form.Files[0];
                    using (var dataStream1 = new MemoryStream())
                    {
                        await file[0].CopyToAsync(dataStream1);
                        addTicketViewModel.Picture1 = dataStream1.ToArray();
                    }
                    file[1] = Request.Form.Files[1];
                    using (var dataStream2 = new MemoryStream())
                    {
                        await file[1].CopyToAsync(dataStream2);
                        addTicketViewModel.Picture2 = dataStream2.ToArray();
                    }
                    file[2] = Request.Form.Files[2];
                    using (var dataStream3 = new MemoryStream())
                    {
                        await file[2].CopyToAsync(dataStream3);
                        addTicketViewModel.Picture3 = dataStream3.ToArray();
                    }
                }


                ApplicationUser NewApplicationUser = context.Users.Find(addTicketViewModel.UserId);

                Ticket newTicket = new Ticket
                {
                    Description = addTicketViewModel.Description,
                    User        = NewApplicationUser,

                    /*PhotoPath1 = uniqueFileName1,
                    *  PhotoPath2 = uniqueFileName2,
                    *  PhotoPath3 = uniqueFileName3,*/
                    Picture1 = addTicketViewModel.Picture1,
                    Picture2 = addTicketViewModel.Picture2,
                    Picture3 = addTicketViewModel.Picture3
                };


                context.Tickets.Add(newTicket);
                context.SaveChanges();

                return(Redirect("/ticket"));
            }
            return(View("Add", addTicketViewModel));
        }
 public void Save()
 {
     context.SaveChanges();
 }
Example #11
0
 public ActionResult Post([FromBody] Ticket tickets)
 {
     context.Add(tickets);
     context.SaveChanges();
     return(new CreatedAtRouteResult("ObtenerTicket", new { id = tickets.id }, tickets));
 }
Example #12
0
 public int Save()
 {
     return(_db.SaveChanges());
 }
Example #13
0
        public Ticket BookTicket(string movieName, DateTime dateTime)
        {
            using (HttpClient client = new HttpClient())

            {
                client.BaseAddress = new Uri("https://localhost:44396/");

                client.DefaultRequestHeaders.Accept.Clear();

                var contentType = new MediaTypeWithQualityHeaderValue("application/json");

                client.DefaultRequestHeaders.Accept.Add(contentType);

                HttpResponseMessage response = client.GetAsync("/api/Movies/GetMovieDetails/" + movieName).Result;

                string apiResponse = response.Content.ReadAsStringAsync().Result;

                //var value = response.Content.ReadAsStringAsync().Result;
                Movie m2 = JsonConvert.DeserializeObject <Movie>(apiResponse);
                if (m2 != null)
                {
                    Ticket ticket = new Ticket()
                    {
                        MovieId   = m2.Id,
                        MovieName = m2.MovieName,
                        Fare      = m2.Fare,
                        Date      = DateTime.Now
                    };
                    _db.Tickets.Add(ticket);
                    _db.SaveChanges();
                    return(ticket);
                }

                /* List<Movie> m= JsonConvert.DeserializeObject<List<Movie>>(apiResponse);
                 * Ticket ticket = new Ticket();
                 * foreach (Movie item in m)
                 * {
                 *   if(item.MovieName==movieName && item.status==true)
                 *   {
                 *
                 *       ticket.MovieId = item.Id;
                 *       ticket.MovieName = item.MovieName;
                 *       ticket.Date = dateTime;
                 *       _db.Tickets.Add(ticket);
                 *       _db.SaveChanges();
                 *       return ticket;
                 *   }
                 * }
                 *
                 *
                 *
                 * }
                 * /*if (m != null)
                 * {
                 * Ticket ticket = new Ticket()
                 * {
                 *   MovieId = m.Id,
                 *   MovieName = m.MovieName,
                 *   Date = DateTime.Now
                 * };
                 * _db.Tickets.Add(ticket);
                 * return ticket;
                 * }*/


                return(null);
            }
        }