Example #1
0
        public PremiumOfferViewModel ToPremiumOfferViewModel(PremiumOffer model)
        {
            var offer = new PremiumOfferViewModel
            {
                Id          = model.Id,
                Title       = model.Title,
                Conditions  = string.IsNullOrEmpty(model.Conditions) ? string.Empty : model.Conditions,
                Quantity    = model.Quantity,
                Price       = model.Price,
                Type        = model.Type,
                Image       = model.Image,
                PartnerName = model.Partner.CompanyName,
                OfferGuidId = model.OfferIdGuid,
            };

            if (model.Flight != null)
            {
                offer.AvailableSeats = model.Flight == null ? -1 : model.Flight.AvailableSeats;
                offer.Arrival        = string.IsNullOrEmpty(model.Flight.Arrival) ? string.Empty : model.Flight.Arrival;
                offer.Departure      = string.IsNullOrEmpty(model.Flight.Departure) ? string.Empty : model.Flight.Departure;
                offer.FlightDateTime = model.Flight.DepartureDate;
            }

            return(offer);
        }
        public async Task <IActionResult> CreateVoucher()
        {
            var partners = await _partnerRepository.GetComboPartners();

            var model = new PremiumOfferViewModel
            {
                PartnersList = partners,
                Type         = PremiumType.Voucher
            };

            return(PartialView("_CreateVoucher", model));
        }
        public async Task <IActionResult> CreateTicket()
        {
            var flights = _flightRepository.GetComboFlightList();

            var partners = await _partnerRepository.GetComboAirlines();

            var model = new PremiumOfferViewModel
            {
                Flights      = flights,
                PartnersList = partners,
                Type         = PremiumType.Ticket
            };

            return(PartialView("_CreateTicket", model));
        }
        public async Task <IActionResult> Edit(PremiumOfferViewModel model)
        {
            try
            {
                var current = await _premiumRepository.GetByIdAsync(model.Id);

                if (current == null)
                {
                    return(new NotFoundViewResult("_Error404"));
                }

                var partner = await _partnerRepository.GetByIdAsync(model.Id);

                var flight = await _flightRepository.GetByIdAsync(model.FlightId);

                current.Flight     = flight ?? null;
                current.Conditions = string.IsNullOrEmpty(model.Conditions) ? string.Empty : model.Conditions;
                current.Partner    = partner;
                current.Quantity   = model.Quantity;
                current.Price      = model.Price;
                current.Status     = 1;
                current.ModifiedBy = await GetCurrentUser();

                current.UpdateDate = DateTime.UtcNow;

                var result = await _premiumRepository.UpdateOfferAsync(current);

                if (!result.Success)
                {
                    return(new NotFoundViewResult("_Error404"));
                }

                //update notification to SuperUser
                result = await _notificationHelper.UpdateNotificationAsync(current.OfferIdGuid, UserType.SuperUser, "");

                if (!result.Success)
                {
                    //if notification does not exist, creates one
                    await _notificationHelper.CreateNotificationAsync(current.OfferIdGuid, UserType.SuperUser, "", EnumHelper.GetType(current.Type));
                }

                return(RedirectToAction(nameof(PremiumIndex)));
            }
            catch (Exception)
            {
                return(new NotFoundViewResult("_Error500"));
            }
        }
 public PremiumOffer ToPremiumOfferModel(PremiumOfferViewModel model, bool isNew, Partner partner, Flight flight)
 {
     return(new PremiumOffer
     {
         Id = isNew ? 0 : model.Id,
         Flight = flight,
         Title = model.Title,
         Quantity = model.Quantity,
         Price = model.Price,
         Partner = partner,
         Conditions = string.IsNullOrWhiteSpace(model.Conditions) ? string.Empty : model.Conditions,
         Type = model.Type,
         Status = 1,
         Image = model.Image,
         OfferIdGuid = isNew ? GuidHelper.CreatedGuid() : model.OfferGuidId,
         CreateDate = model.CreatedOn
     });
 }
        public async Task <IActionResult> CreateOffer(PremiumOfferViewModel model)
        {
            try
            {
                var partner = await _partnerRepository.GetByIdAsync(model.PartnerId);

                if (partner == null)
                {
                    return(new NotFoundViewResult("_Error404"));
                }

                var flight = await _flightRepository.GetByIdAsync(model.FlightId);

                if ((model.Type == PremiumType.Ticket || model.Type == PremiumType.Upgrade) && flight == null)
                {
                    return(new NotFoundViewResult("_Error404"));
                }

                var offer = _converter.ToPremiumOfferModel(model, true, partner, flight);
                offer.CreatedBy = await GetCurrentUser();

                offer.CreateDate = DateTime.UtcNow;

                var result = await _premiumRepository.CreateEntryAsync(offer);

                if (!result.Success)
                {
                    return(new NotFoundViewResult("_Error404"));
                }
                //send notification to superuser
                await _notificationHelper.CreateNotificationAsync(offer.OfferIdGuid, UserType.SuperUser, "", EnumHelper.GetType(offer.Type));

                return(RedirectToAction(nameof(PremiumIndex)));
            }
            catch (Exception exception)
            {
                ModelState.AddModelError(string.Empty, exception.Message);
            }
            return(RedirectToAction(nameof(PremiumIndex)));
        }
        public PremiumOfferViewModel ToPremiumOfferViewModel(PremiumOffer model)
        {
            var offer = new PremiumOfferViewModel
            {
                Id             = model.Id,
                Title          = model.Title,
                FlightId       = model.Flight == null ? 0 : model.Flight.Id,
                Conditions     = string.IsNullOrEmpty(model.Conditions) ? string.Empty : model.Conditions,
                Quantity       = model.Quantity,
                Price          = model.Price,
                AvailableSeats = model.Flight == null ? -1 : model.Flight.AvailableSeats,
                Type           = model.Type,
                Image          = model.Image,
                PartnerName    = model.Partner.CompanyName,
                OfferGuidId    = model.OfferIdGuid,
                Arrival        = model.Flight != null ? (string.IsNullOrEmpty(model.Flight.Arrival) ? string.Empty : model.Flight.Arrival) : string.Empty,
                Departure      = model.Flight != null ? (string.IsNullOrEmpty(model.Flight.Departure) ? string.Empty : model.Flight.Departure) : string.Empty,
                FlightDateTime = model.Flight != null ? model.Flight.DepartureDate : new DateTime?(),
                CreatedOn      = model.CreateDate
            };

            return(offer);
        }