Example #1
0
        public PromocodeDTO VerifyPromocode(string promocode, int userId)
        {
            try
            {
                Promocode    code     = _dbContext.Promocodes.FirstOrDefault(x => x.Code == promocode && x.IsDeleted == false && (x.User_Id == null || x.User_Id == userId));
                PromocodeDTO response = new PromocodeDTO();

                if (code != null)
                {
                    if (code.ActivationDate.Date <= DateTime.UtcNow.Date && code.ExpiryDate >= DateTime.UtcNow.Date && code.LimitOfUsage > 0 && code.IsExpired == false)
                    {
                        if (code.LimitOfUsage-- <= 0)
                        {
                            code.IsExpired = true;
                        }

                        _dbContext.SaveChanges();
                        return(null);
                    }
                    if (_dbContext.UserPromocode.Any(x => x.User_Id == userId && x.Promocode_Id == code.Id))
                    {
                        return(response);
                    }

                    Mapper.Map(code, response);
                    return(response);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #2
0
        public List <RideTypeDTO> GetAllRideTypes(CultureType culture, int estimatedTime, double distanceInKm, string promocode, string PickupCity, string DestinationCity, PaymentMethods paymentType, int?userId, out int promoId)
        {
            try
            {
                List <RideType>    RideTypeList         = _dbContext.RideTypes.Include(x => x.RideTypeMLsList).Where(x => x.Culture == CultureType.Both || x.Culture == culture && x.IsDeleted == false).ToList();
                List <RideTypeDTO> RideTypeResponseList = Mapper.Map <List <RideType>, List <RideTypeDTO> >(RideTypeList);
                RideTypeDTO        RideTypeDTO          = new RideTypeDTO();
                promoId = 0;
                FareCalculation fare = null;
                if (!String.IsNullOrEmpty(PickupCity) && !String.IsNullOrEmpty(DestinationCity))
                {
                    var pickup      = _dbContext.CityMLs.FirstOrDefault(x => x.Name.ToLower().Equals(PickupCity) && x.City.IsDeleted == false && x.City.IsActive == true);
                    var destination = _dbContext.CityMLs.FirstOrDefault(x => x.Name.ToLower().Equals(DestinationCity) && x.City.IsDeleted == false && x.City.IsActive == true);
                    if (pickup == null || destination == null)
                    {
                        return(null);
                    }

                    fare = _dbContext.FareCalculations.FirstOrDefault(x => x.City_Id == pickup.City_Id && x.StartTime <DateTime.UtcNow.TimeOfDay && x.EndTime> DateTime.UtcNow.TimeOfDay && x.PaymentMethod == paymentType);
                }

                for (int i = 0; i < RideTypeList.Count; i++)
                {
                    RideTypeML rideTypeML = RideTypeList[i].RideTypeMLsList.FirstOrDefault(x => x.Culture == culture);
                    Mapper.Map(rideTypeML, RideTypeResponseList[i]);

                    if (distanceInKm > 0)
                    {
                        if (fare != null)
                        {
                            RideTypeResponseList[i].EstimatedFare = fare.BasicCharges + (distanceInKm * fare.FarePerKM) + (estimatedTime * fare.FarePerMin);
                        }
                        else
                        {
                            RideTypeResponseList[i].EstimatedFare = RideTypeList[i].BasicCharges + (distanceInKm * RideTypeList[i].FarePerKM) + (estimatedTime * RideTypeList[i].FarePerMin);
                        }
                    }

                    if (!String.IsNullOrEmpty(promocode))
                    {
                        Promocode    code     = _dbContext.Promocodes.FirstOrDefault(x => x.Code == promocode && x.IsDeleted == false && x.ActivationDate.Date <= DateTime.UtcNow.Date && x.ExpiryDate.Date >= DateTime.UtcNow.Date && x.LimitOfUsage > x.UsageCount && x.IsExpired == false && (x.User_Id == null || x.User_Id == userId));
                        PromocodeDTO response = new PromocodeDTO();

                        if (code != null)
                        {
                            if (code.Type == PromocodeType.FixedDiscount)
                            {
                                RideTypeResponseList[i].EstimatedFare = RideTypeResponseList[i].EstimatedFare - code.Discount;
                            }
                            else if (code.Type == PromocodeType.DiscountPercentage)
                            {
                                RideTypeResponseList[i].EstimatedFare = RideTypeResponseList[i].EstimatedFare * ((100 - code.Discount) / 100);
                            }

                            promoId = code.Id;
                        }
                    }
                }
                return(RideTypeResponseList);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }