public ActionResult _ReviewList(HttpPostedFileBase file)
        {
            List <PreValidatedStudent> scholars = new List <PreValidatedStudent>();
            var            excel     = new ExcelPackage(file.InputStream);
            ExcelWorksheet worksheet = excel.Workbook.Worksheets[1];

            //validation
            for (int i = 12; i <= worksheet.Dimension.End.Row; i++)
            {
                //validation

                //scholarhsip type, student id
                //loop all columns in a row
                string              studentID     = worksheet.Cells[i, 4].Value.ToString();
                int                 scholarshipID = Convert.ToInt32(worksheet.Cells[i, 5].Value);
                Scholarship         type          = db.Scholarships.Where(e => e.ScholarshipID.Equals(scholarshipID)).FirstOrDefault();
                ValidationPeriod    period        = db.WebSettings.FirstOrDefault().ValidationPeriod;
                AspNetUser          user          = db.AspNetUsers.Where(e => e.UserProfiles.FirstOrDefault().StudentProfile.StudentID.Equals(studentID)).FirstOrDefault();
                PreValidatedStudent tempScholar   = new PreValidatedStudent();


                tempScholar.ScholarshipID    = type.ScholarshipID;
                tempScholar.PeriodID         = period.PeriodID;
                tempScholar.UserID           = user.Id;
                tempScholar.Scholarship      = type;
                tempScholar.ValidationPeriod = period;
                tempScholar.AspNetUser       = user;

                scholars.Add(tempScholar);
            }
            TempData["Scholars"] = scholars;
            return(PartialView("_ReviewList", scholars));
        }
Exemplo n.º 2
0
 internal static InternalValidationPeriod CreateAdvanced(ValidationPeriod period)
 {
     return(new InternalValidationPeriod
     {
         ValidationType = DateValidationType.Advanced,
         Period = period,
     });
 }
Exemplo n.º 3
0
        public ActionResult AddPeriod(ValidationPeriod period)
        {
            period.AcademicYearEnd = period.AcademicYearStart + 1;
            db.ValidationPeriods.Add(period);
            db.SaveChanges();
            TempData["Message"]     = "Period Successfully Added";
            TempData["MessageType"] = "success";

            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
            private static bool IsPeriodActiveForDayAndTime(ValidationPeriod period, DayOfWeek day, TimeSpan time, bool testOnlyAfterMidnight)
            {
                var configuration = new PeriodRangeConfiguration
                {
                    StartTime                = period.StartingTimeForDay(day),
                    EndTime                  = period.EndingTimeForDay(day),
                    EndsTomorrow             = period.IsEndTimeAfterMidnightForDay(day),
                    IsActiveOnlyWithinBounds = period.IsTimeBoundedForDay(day),
                };

                int currentTime = Convert.ToInt32(time.TotalSeconds);

                return(IsTimeActiveForConfiguration(currentTime, configuration, testOnlyAfterMidnight));
            }
            /// <summary>
            /// Fetch all price adjustments for the given items, striped by item Id and dimension Id.
            /// </summary>
            /// <param name="items">The set of items to search by. Set of pairs of item Id and variant dimension Id. Ignores the unit.</param>
            /// <param name="priceGroups">Set of price groups to search by.</param>
            /// <param name="minActiveDate">The earliest inclusive active date to search by. Must be less than or equal to maxActiveDate.</param>
            /// <param name="maxActiveDate">The latest inclusive active date to search by. Must be greater than or equal to minActiveDate.</param>
            /// <param name="settings">The query result settings.</param>
            /// <returns>Collection of price adjustments striped by item Id and variant dimension Id (if any) of type ReadOnlyCollection&lt;PriceAdjustment&gt;.</returns>
            public object ReadPriceAdjustments(
                object items,
                object priceGroups,
                DateTimeOffset minActiveDate,
                DateTimeOffset maxActiveDate,
                QueryResultSettings settings)
            {
                IEnumerable <ItemUnit> itemSet       = items as IEnumerable <ItemUnit>;
                ISet <string>          priceGroupSet = priceGroups as ISet <string>;
                ReadOnlyCollection <ValidationPeriod> validationPeriods;
                ReadOnlyCollection <PriceAdjustment>  priceAdjustments;

                using (SimpleProfiler profiler = new SimpleProfiler("ReadPriceAdjustments", 1))
                {
                    var dataRequest = new ReadPriceAdjustmentsDataRequest(
                        itemSet,
                        priceGroupSet,
                        minActiveDate,
                        maxActiveDate);
                    dataRequest.QueryResultSettings = settings;
                    priceAdjustments = this.ExecuteDataService <PriceAdjustment, ValidationPeriod>(dataRequest, out validationPeriods);
                }

                IDictionary <string, ValidationPeriod> validationPeriodLookup = validationPeriods.ToDictionary(p => p.PeriodId, p => p, StringComparer.OrdinalIgnoreCase);

                foreach (PriceAdjustment adjustment in priceAdjustments)
                {
                    if (!string.IsNullOrWhiteSpace(adjustment.ValidationPeriodId))
                    {
                        ValidationPeriod validationPeriod = null;
                        if (validationPeriodLookup.TryGetValue(adjustment.ValidationPeriodId, out validationPeriod))
                        {
                            adjustment.ValidationPeriod = validationPeriod;
                        }
                    }
                }

                return(priceAdjustments);
            }
        public ActionResult UploadList(List <PreValidatedStudent> scholars)
        {
            scholars = (List <PreValidatedStudent>)TempData["Scholars"];

            int counter = 0;

            foreach (var item in scholars)
            {
                counter++;
                Scholarship      type   = db.Scholarships.Where(e => e.ScholarshipID.Equals(item.ScholarshipID)).FirstOrDefault();
                ValidationPeriod period = db.WebSettings.FirstOrDefault().ValidationPeriod;
                AspNetUser       user   = db.AspNetUsers.Where(e => e.Id.Equals(item.UserID)).FirstOrDefault();

                item.Scholarship      = type;
                item.ValidationPeriod = period;
                item.AspNetUser       = user;
                db.PreValidatedStudents.Add(item);
            }
            db.SaveChanges();
            //redirect to select scholarship
            TempData["Message"] = string.Format("Scholars Successfuly Added. Number of added scholars {0}", counter);
            return(RedirectToAction("UploadList", "Admin"));
        }
Exemplo n.º 7
0
            /// <summary>
            /// Validate date against validation period.
            /// </summary>
            /// <param name="validationType">Validation type.</param>
            /// <param name="validationPeriod">Validation period.</param>
            /// <param name="startDate">Pricing start date.</param>
            /// <param name="endDate">Pricing end date.</param>
            /// <param name="dateToCheck">Date to check.</param>
            /// <returns>True if it's valid.</returns>
            public static bool ValidateDateAgainstValidationPeriod(DateValidationType validationType, ValidationPeriod validationPeriod, DateTimeOffset startDate, DateTimeOffset endDate, DateTimeOffset dateToCheck)
            {
                InternalValidationPeriod validation;
                bool promoPeriodValid = false;

                switch (validationType)
                {
                case DateValidationType.Advanced:
                    validation       = InternalValidationPeriod.CreateAdvanced(validationPeriod);
                    promoPeriodValid = validation.IsActive(dateToCheck);
                    break;

                case DateValidationType.Standard:
                    validation       = InternalValidationPeriod.CreateStandard(startDate: startDate, endDate: endDate);
                    promoPeriodValid = validation.IsActive(dateToCheck);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("validationType", "Invalid Discount Validation Type: " + validationType);
                }

                return(promoPeriodValid);
            }
Exemplo n.º 8
0
            private static bool IsValidationPeriodActive(ValidationPeriod validationPeriod, DateTimeOffset transDateTime)
            {
                if (validationPeriod == null || string.IsNullOrEmpty(validationPeriod.PeriodId))
                {
                    // If no period Id given, then it is always a valid period
                    return(true);
                }

                DateTime transDate = transDateTime.Date;
                TimeSpan transTime = transDateTime.TimeOfDay;

                // Is the discount valid within the start and end date period?
                if (InternalValidationPeriod.IsDateWithinStartEndDate(transDate, validationPeriod.ValidFrom.Date, validationPeriod.ValidTo.Date))
                {
                    bool answerFound = false;
                    bool isActive    = false;

                    // does today's configuration tell if period is active?
                    if (IsRangeDefinedForDay(validationPeriod, transDate.DayOfWeek))
                    {
                        isActive    = IsPeriodActiveForDayAndTime(validationPeriod, transDate.DayOfWeek, transTime, false);
                        answerFound = true;
                    }

                    // if we don't know or got negative result, see if yesterday will activate it (if its range ends after midnight)
                    DayOfWeek yesterday = transDate.AddDays(-1).DayOfWeek;
                    bool      lastRangeDefinedAfterMidnight =
                        IsRangeDefinedForDay(validationPeriod, yesterday) && validationPeriod.IsEndTimeAfterMidnightForDay(yesterday);

                    if ((!answerFound || isActive == false) && lastRangeDefinedAfterMidnight)
                    {
                        // if yesterday makes it active, set isActive = true
                        isActive    = IsPeriodActiveForDayAndTime(validationPeriod, yesterday, transTime, true);
                        answerFound = true;
                    }

                    // if we still don't know, try using general configuration
                    if (!answerFound)
                    {
                        var configuration = new PeriodRangeConfiguration
                        {
                            StartTime = validationPeriod.StartingTime,
                            EndTime   = validationPeriod.EndingTime,
                            IsActiveOnlyWithinBounds = validationPeriod.IsTimeBounded != 0,
                            EndsTomorrow             = validationPeriod.IsEndTimeAfterMidnight != 0
                        };

                        if ((validationPeriod.StartingTime != 0) && (validationPeriod.EndingTime != 0))
                        {
                            int currentTime = Convert.ToInt32(transTime.TotalSeconds);
                            isActive    = IsTimeActiveForConfiguration(currentTime, configuration, false);
                            answerFound = true;
                        }
                    }

                    return(answerFound ? isActive : (validationPeriod.IsTimeBounded == 1));
                }

                // not within date range, so active if not set to be within date range
                return(validationPeriod.IsTimeBounded != 1);
            }
Exemplo n.º 9
0
 private static bool IsRangeDefinedForDay(ValidationPeriod period, DayOfWeek day)
 {
     return((period.StartingTimeForDay(day) != 0) && (period.EndingTimeForDay(day) != 0));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OfferDiscount" /> class.
 /// </summary>
 /// <param name="validationPeriod">Validation period.</param>
 public OfferDiscount(ValidationPeriod validationPeriod)
     : base(validationPeriod)
 {
 }