Exemplo n.º 1
0
        public async Task <IActionResult> Edit(string fromOffice, string toOffice, Trip trip, TicketStatusEnum ticketStatus, CarRentalEnum rentalCarStatus, AccomodationStatusEnum accomodationStatus)
        {
            try
            {
                var office1 = _context.Office.SingleOrDefault(x => x.Name == fromOffice);
                var office2 = _context.Office.SingleOrDefault(x => x.Name == toOffice);
                trip.ToOffice   = office2.Id;
                trip.FromOffice = office1.Id;

                user             = _us.GetUserFromRequest(Request);
                trip.Organizator = user.Id;
                _context.Update(trip);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException a)
            {
                if (!TripExists(trip.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            var flightInfo = _context.FlightInformation.Single(a => a.TripId == trip.Id);

            flightInfo.FlightTicketStatus = ticketStatus;

            var rentalCar = _context.RentalCarInformation.Single(a => a.TripId == trip.Id);

            rentalCar.CarRental = rentalCarStatus;

            var accomodationList = _context.AccomodationInfo.Where(a => a.TripId == trip.Id).ToList();

            for (int i = 0; i < accomodationList.Count; i++)
            {
                var tempAccomodation = accomodationList[i];
                tempAccomodation.AccomodationStatus = accomodationStatus;
            }



            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 2
0
        public IActionResult Create(string officeTitle1, string officeTitle2, Trip trip, TicketStatusEnum ticketStatus, CarRentalEnum carRental, AccomodationStatusEnum accomodationStatus)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    var office1 = _context.Office.SingleOrDefault(x => x.Name == officeTitle1);
                    var office2 = _context.Office.SingleOrDefault(x => x.Name == officeTitle2);
                    trip.ToOffice   = office2.Id;
                    trip.FromOffice = office1.Id;
                    trip.TripStatus = 0;

                    user             = _us.GetUserFromRequest(Request);
                    trip.Organizator = user.Id;
                    _context.Add(trip);
                    //await _context.SaveChangesAsync();
                    Console.WriteLine(trip.Id);


                    trip.Participators = new List <TripParticipator>();
                    int i1 = 0;
                    if (list == null || list.Count() == 0)
                    {
                        return(RedirectToAction(nameof(Create), new { error = "Kelionėje turi dalyvauti bent vienas dalyvis" }));
                    }
                    list = list.Distinct().ToList();
                    foreach (int i in list)
                    {
                        TripParticipator participator = new TripParticipator();
                        participator.TripId  = trip.Id;
                        participator.UserId  = i;
                        participator.Approve = false;
                        if (i1 != i)
                        {
                            trip.Participators.Add(participator);
                        }
                        i1 = i;
                    }
                    if (!_ts.IsTripParticipatorsBusy(trip))
                    {
                        _context.Add(trip);
                        _context.SaveChanges();

                        foreach (TripParticipator tripParticipator in trip.Participators)
                        {
                            var accomodationInfo = new AccomodationInfo()
                            {
                                TripId = trip.Id, UserId = tripParticipator.UserId, Start = DateTime.MinValue, End = DateTime.MinValue, AccomodationStatus = accomodationStatus
                            };
                            _context.Add(accomodationInfo);
                        }

                        var flightInfo = new FlightInformation()
                        {
                            TripId = trip.Id, Cost = 0, Start = DateTime.MinValue, End = DateTime.MinValue, FlightTicketStatus = ticketStatus
                        };
                        _context.Add(flightInfo);
                        var rentalCarinfo = new RentalCarInformation()
                        {
                            TripId = trip.Id, Cost = 0, Start = DateTime.MinValue, End = DateTime.MinValue, CarRental = carRental
                        };
                        _context.Add(rentalCarinfo);

                        _context.SaveChanges();
                        transaction.Commit();
                        return(RedirectToAction(nameof(Index)));
                    }
                    else
                    {
                        return(RedirectToAction(nameof(Create), new { error = "Pasirinkti dalyiai šiuo laiku užimti" }));
                    }
                }
                catch (Exception)
                {
                    return(NotFound());
                }
            }
        }