Пример #1
0
        public static CheckResult ValidateSave(DSModel db, UserModel user)
        {
            CheckResult res = new CheckResult();

            if (string.IsNullOrWhiteSpace(user.Username))
            {
                res.AddError("Please enter a Username!", user.GetName(p => p.Username));
            }
            if (string.IsNullOrWhiteSpace(user.FirstName))
            {
                res.AddError("Please enter a First Name!", user.GetName(p => p.FirstName));
            }
            if (string.IsNullOrWhiteSpace(user.LastName))
            {
                res.AddError("Please enter a Last Name!", user.GetName(p => p.LastName));
            }

            var check = db.Users.Where(u => u.Username == user.Username && u.UserID != user.UserID).FirstOrDefault();

            if (check != null)
            {
                res.AddError("Another user already uses this username!", user.GetName(p => p.Username));
            }

            return(res);
        }
Пример #2
0
        public static CheckResult ValidateSave(DSModel db, CompanyModel model)
        {
            CheckResult res = new CheckResult(model);

            if (string.IsNullOrWhiteSpace(model.CompanyName))
            {
                res.AddError("Please enter a Company Name!", model.GetName(p => p.CompanyName));
            }
            if (model.CompanyCode != string.Empty)
            {
                var check = db.Companies.Where(c => c.CompanyCode == model.CompanyCode && c.CompanyID != model.CompanyID).FirstOrDefault();
                if (check != null)
                {
                    res.AddError("Another company already uses this Company Code! Use Peek or leave blank to autogenerate!", model.GetName(p => p.CompanyCode));
                }
            }
            if (model.TrainingTime < 0m)
            {
                res.AddError("Traning time cannot be negative number!", model.GetName(p => p.TrainingTime));
            }

            var groups = model.Locations.GroupBy(l => l.LocationCode).ToList();

            if (groups.Any(g => g.Count() > 1))
            {
                var gr = groups.Where(g => g.Count() > 1).FirstOrDefault();
                res.AddError(string.Format("Duplicate location codes! Code: {0}", gr.FirstOrDefault().LocationCode));
            }
            return(res);
        }
Пример #3
0
        /// <summary>
        /// Checks the integrity of the Chunk. Reports Error Messages if values are missing
        /// </summary>
        /// <returns></returns>
        public override CheckResult CheckIntegrity()
        {
            CheckResult result = new CheckResult();

            if (BoundingBox == null)
            {
                result.AddError("Bounding Box of Geometry is set to NULL!");
            }

            if (Segments.Count == 0)
            {
                result.AddError("Number of Segments in Geometry is zero! At least one Segment is necessary!");
            }

            try {
                result = CheckResult.Merge(result, CheckResult.Merge(Segments.ToArray()));
            }
            catch (ArgumentNullException ex) {
                result.AddError(ex.Message);
                return(result);
            }

            /*catch {
             *  throw;
             *  ///result.AddError("An Unknown Error occured! " + ex.Message);
             *  //return result;
             * }*/

            return(result);
        }
Пример #4
0
        public static CheckResult ValidateSave(DSModel db, DriverMedicalModel model)
        {
            CheckResult res = new CheckResult(model);

            if (model.DriverID == 0)
            {
                res.AddError("Driver cannot be empty!", model.GetName(p => p.DriverID));
            }
            if (model.MedTypeID == 0)
            {
                res.AddError("Medical type cannot be empty!", model.GetName(p => p.MedTypeID));
            }
            if (model.ExaminationDate == DateTime.MinValue)
            {
                res.AddError("Examination date cannot be empty!", model.GetName(p => p.ExaminationDate));
            }
            if (model.ValidityDate == DateTime.MinValue)
            {
                res.AddError("Validity date cannot be empty!", model.GetName(p => p.ValidityDate));
            }
            if (model.ValidityDate.Date <= model.ExaminationDate.Date)
            {
                res.AddError("Validity date cannot be earlier than Examination date!", model.GetName(p => p.ValidityDate));
            }

            return(res);
        }
Пример #5
0
        /// <summary>
        /// Checks the integrity of the Chunk. Reports Error Messages if values are missing
        /// </summary>
        /// <returns></returns>
        public override CheckResult CheckIntegrity() {
            CheckResult result = new CheckResult();

            if (Name == null) {
                result.AddError("Name of the Selection is set to NULL! Must be a string!");
            }

            if (FrameInformation == null) {
                result.AddError("Frame Information of the Selection is set to NULL!");
            }

            if (BoundingBox == null) {
                result.AddError("Bounding Box of the Selection is set to NULL!");
            }


            try {
                result = CheckResult.Merge(result, FrameInformation.CheckIntegrity(), BoundingBox.CheckIntegrity());
            }
            catch (ArgumentNullException ex) {
                result.AddError(ex.Message);
                return result;
            }
            catch (Exception ex) {
                result.AddError("An Unknown Error occured! " + ex.Message);
                return result;
            }

            return result;
        }
Пример #6
0
        public static CheckResult ValidateSave(DSModel db, InvoiceModel model)
        {
            CheckResult res = new CheckResult(model);

            if (model.CompanyID == 0)
            {
                res.AddError("Please choose a Company!", model.GetName(p => p.CompanyID));
            }
            if (model.LocationID == 0)
            {
                res.AddError("Please choose a Location!", model.GetName(p => p.LocationID));
            }
            if (model.InvoicePeriodFrom == DateTime.MinValue)
            {
                res.AddError("Please enter a date for Period From!", model.GetName(p => p.InvoicePeriodFrom));
            }
            if (model.InvoicePeriodTo == DateTime.MinValue)
            {
                res.AddError("Please enter a date for Period To!", model.GetName(p => p.InvoicePeriodTo));
            }
            if (model.InvoicePeriodTo < model.InvoicePeriodFrom)
            {
                res.AddError("The date for Pertiod To cannot be earlier than Period From!", model.GetName(p => p.InvoicePeriodTo));
            }

            return(res);
        }
        public static CheckResult ValidateSave(DSModel db, DispatchModel model)
        {
            CheckResult res = new CheckResult(model);

            if (model.DriverID == 0)
            {
                res.AddError("Please choose a Driver!", model.GetName(p => p.DriverID));
            }
            if (model.CompanyID == 0)
            {
                res.AddError("Please choose a Company!", model.GetName(p => p.CompanyID));
            }
            if (model.LocationID == 0)
            {
                res.AddError("Please choose a Location!", model.GetName(p => p.LocationID));
            }
            if (model.ToDateTime < model.FromDateTime)
            {
                res.AddError("End Date Time cannot be earlier than Start Date Time!", model.GetName(p => p.ToDateTime));
            }
            if (model.TrainingTime < 0.0m)
            {
                res.AddError("Training time cannot be negative!", model.GetName(p => p.TrainingTime));
            }
            if (model.MiscCharge < 0m)
            {
                res.AddError("Per diem cannot be negative!", model.GetName(p => p.MiscCharge));
            }

            var checkLicense = db.DriversLicenses
                               .Where(d => d.DriverID == model.DriverID &&
                                      d.IssueDate <= model.FromDateTime.Date &&
                                      d.ExpirationDate >= model.ToDateTime)
                               .Count();

            if (checkLicense == 0)
            {
                res.AddError("Driver has no valid license for the specified dispatch dates!", model.GetName(p => p.DriverID));
            }

            //overlap check
            var check = db.Dispatches
                        .Where(d =>
                               d.DispatchID != model.DispatchID &&
                               d.DriverID == model.DriverID &&
                               d.FromDateTime <model.ToDateTime &&
                                               d.ToDateTime> model.FromDateTime)
                        .FirstOrDefault();

            if (check != null)
            {
                res.AddError(string.Format("This driver has overlapping dispatches!\r\n\r\nCompany: {0}\r\nLocation: {1}\r\nStart: {2}\r\nEnd: {3}",
                                           check.Company.CompanyName,
                                           check.Location.LocationName,
                                           check.FromDateTime.ToString("g"),
                                           check.ToDateTime.ToString("g")), model.GetName(p => p.FromDateTime));
            }

            return(res);
        }
Пример #8
0
        public static CheckResult ValidateDriverRates(DSModel db, List <CompanyLicensePayRateModel> rates)
        {
            var         dic = db.ConstLicenses.ToDictionary(d => d.LicenseID, d => d.LicenseName);
            CheckResult res = new CheckResult();

            for (int i = 0; i < rates.Count; i++)
            {
                var cur = rates[i];
                if (cur.ToDate.HasValue && cur.ToDate.Value.Date < cur.FromDate.Date)
                {
                    res.AddError(
                        string.Format("To date cannot be earlier than From date! License: {0} From: {1} To: {2}",
                                      dic[cur.LicenseID],
                                      cur.FromDate.ToString(GLOB.Formats.Date),
                                      cur.ToDate.GetValueOrDefault().ToString(GLOB.Formats.Date)),
                        cur.GetName(p => p.ToDate));
                    return(res);
                }

                if (rates.Count > 1)
                {
                    for (int q = 0; q < rates.Count; q++)
                    {
                        if (q == i)
                        {
                            continue;
                        }

                        //overlap = ! ( (end2 < start1) || (start2 > end1) );
                        var next = rates[q];
                        if (!((next.ToDate.HasValue && next.ToDate.Value.Date < cur.FromDate.Date) || (cur.ToDate.HasValue && next.FromDate.Date > cur.ToDate.Value.Date)) &&
                            next.LicenseID == cur.LicenseID)
                        {
                            res.AddError(
                                string.Format("Overlapping driver dates detected!\r\n\r\nLicense: {0} From: {1} To: {2}\r\nLicense: {3} From: {4} To: {5}",
                                              dic[cur.LicenseID],
                                              cur.FromDate.ToString(GLOB.Formats.Date),
                                              (cur.ToDate.HasValue ? cur.ToDate.GetValueOrDefault().ToString(GLOB.Formats.Date) : "NOW"),
                                              dic[next.LicenseID],
                                              next.FromDate.ToString(GLOB.Formats.Date),
                                              (next.ToDate.HasValue ? next.ToDate.GetValueOrDefault().ToString(GLOB.Formats.Date) : "NOW"))
                                , cur.GetName(p => p.ToDate));
                            return(res);
                        }
                    }
                }
            }

            return(res);
        }
Пример #9
0
        public static CheckResult ValidateSaveView(DSModel db, FileBlobViewModel model)
        {
            CheckResult res = new CheckResult(model);

            if (string.IsNullOrWhiteSpace(model.BlobName))
            {
                res.AddError("File name cannot bet empty!", model.GetName(p => p.BlobName));
            }
            if (string.IsNullOrWhiteSpace(model.BlobExtension))
            {
                res.AddError("File extension cannot be empty!", model.GetName(p => p.BlobExtension));
            }

            return(res);
        }
Пример #10
0
        /// <summary>
        /// Checks the integrity of the Chunk. Reports Error Messages if values are missing
        /// </summary>
        /// <returns></returns>
        public override CheckResult CheckIntegrity()
        {
            CheckResult result = new CheckResult();

            if (Name == null)
            {
                result.AddError("Name of the Camera is set to NULL! Must be a string!");
            }

            return(result);
        }
Пример #11
0
        /// <summary>
        /// Checks the integrity of the Chunk. Reports Error Messages if values are missing
        /// </summary>
        /// <returns></returns>
        public override CheckResult CheckIntegrity()
        {
            CheckResult result = new CheckResult();

            if (vertices.Count < 3)
            {
                result.AddError("A Polygon needs at least 3 Vertices but " + vertices.Count + " are provided!");
            }

            return(result);
        }
Пример #12
0
        /// <summary>
        /// Checks the integrity of the Chunk. Reports Error Messages if values are missing
        /// </summary>
        /// <returns></returns>
        public override CheckResult CheckIntegrity()
        {
            CheckResult result = new CheckResult();

            if (Name == null)
            {
                result.AddError("Name of Model (Index No " + index + ") is set to NULL! Must be a string!");
            }

            if (Type == MTYP.Null && Geometry != null)
            {
                result.AddError(Name + ": Model Type is set to NULL but Geometry Information is present. Geometry will be lost!");
            }

            if (Type == MTYP.Static && Geometry == null)
            {
                result.AddError(Name + ": Model Type is set to " + Type.ToString() + " but Geometry Information is NULL!");
            }

            return(result);
        }
Пример #13
0
        /// <summary>
        /// Checks the integrity of the Chunk. Reports Error Messages if values are missing
        /// </summary>
        /// <returns></returns>
        public override CheckResult CheckIntegrity()
        {
            CheckResult result = new CheckResult();

            if (Material == null)
            {
                result.AddError("Material of Mesh Segment is set to NULL!");
            }

            if (vertices.Count == 0)
            {
                result.AddError("No vertices set in Mesh Segment!");
            }

            if (polygons.Count == 0)
            {
                result.AddError("No polygons set in Mesh Segment!");
            }

            return(result);
        }
Пример #14
0
        /// <summary>
        /// Checks the integrity of the Chunk. Reports Error Messages if values are missing
        /// </summary>
        /// <returns></returns>
        public override CheckResult CheckIntegrity()
        {
            CheckResult result = new CheckResult();

            if (Name == null)
            {
                result.AddError("Name of the Material is set to NULL! Must be a string!");
            }

            if (specularSharpness < 0)
            {
                result.AddError(Name + ": Negative values for Specular Sharpness are not allowed!");
            }

            if (specularSharpness < 0)
            {
                result.AddError(Name + ": Negative values for Attribute are not allowed!");
            }

            return(result);
        }
Пример #15
0
        public static CheckResult ValidateSave(DSModel db, DriverLicenseModel model)
        {
            CheckResult res = new CheckResult(model);

            if (model.DriverID == 0)
            {
                res.AddError("Driver cannot be empty!", model.GetName(p => p.DriverID));
            }
            if (model.LicenseID == 0)
            {
                res.AddError("License type cannot be empty!", model.GetName(p => p.LicenseID));
            }
            if (model.IssueDate == DateTime.MinValue)
            {
                res.AddError("Issue date cannot be empty!", model.GetName(p => p.IssueDate));
            }
            if (model.ExpirationDate == DateTime.MinValue)
            {
                res.AddError("Expiration date cannot be empty!", model.GetName(p => p.ExpirationDate));
            }
            if (model.MVRReviewDate.HasValue && model.MVRReviewDate.Value.Date < model.IssueDate.Date)
            {
                res.AddError("MVR review date cannot be earlier than Issue date!", model.GetName(p => p.MVRReviewDate));
            }
            if (model.IssueDate.Date > model.ExpirationDate.Date)
            {
                res.AddError("Expiration date cannot be earlier than Issue date!", model.GetName(p => p.ExpirationDate));
            }
            if (model.Permits.Count == 0)
            {
                res.AddError("At least one permit must be selected!", model.GetName(p => p.Permits));
            }

            //overlap check
            var check = db.DriversLicenses
                        .Where(d =>
                               d.DriverLicenseID != model.DriverLicenseID &&
                               d.DriverID == model.DriverID &&
                               d.IssueDate <model.ExpirationDate &&
                                            d.ExpirationDate> model.IssueDate)
                        .FirstOrDefault();

            if (check != null)
            {
                res.AddError("There is an overlapping license already!");
            }

            return(res);
        }
Пример #16
0
        /// <summary>
        /// Does an integrity check to see if all values are properly set and in a valid range
        /// </summary>
        /// <returns>Contains all found errors</returns>
        public CheckResult CheckIntegrity()
        {
            CheckResult result = new CheckResult();

            //check for double uses of model indices
            for (int i = 0; i < Models.Count - 1; i++)
            {
                for (int j = i + 1; j < Models.Count; j++)
                {
                    if (Models[i].Index == Models[j].Index)
                    {
                        result.AddError(
                            string.Format(
                                "The Model Index {0} is used by both {1} and {2}",
                                Models[i].Index,
                                Models[i].Name,
                                Models[j].Name
                                )
                            );
                    }
                }
            }

            try {
                result = CheckResult.Merge(result, CheckResult.Merge(SelectionInformation));
                result = CheckResult.Merge(result, CheckResult.Merge(Materials.ToArray()));
                result = CheckResult.Merge(result, CheckResult.Merge(Models.ToArray()));
            }
            catch (ArgumentNullException ex) {
                result.AddError(ex.Message);
                return(result);
            }
            catch (Exception ex) {
                result.AddError("An Unknown Error occured! " + ex.Message);
                return(result);
            }

            return(result);
        }
Пример #17
0
        public static CheckResult ValidateDelete(DSModel db, DriverLicenseModel model)
        {
            CheckResult res = new CheckResult(model);

            var checkDispatch = db.Dispatches
                                .Where(d => d.DriverID == model.DriverID &&
                                       d.FromDateTime.Date >= model.IssueDate &&
                                       d.ToDateTime.Date <= model.ExpirationDate)
                                .FirstOrDefault();

            if (checkDispatch != null)
            {
                res.AddError("Cannot delete license, a dispatch uses the license!");
            }

            return(res);
        }
Пример #18
0
        public CheckResult PreviewFile(FileBlobViewModel model)
        {
            CheckResult res = new CheckResult(model);

            using (var db = DB.GetContext())
            {
                var file = FileBlobRepository.GetBlob(db, model.BlobID);
                if (file == null)
                {
                    res.AddError("No such file!", string.Empty);
                    return(res);
                }

                string directory = Path.Combine(Environment.CurrentDirectory, "files");
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                string fileName = Path.Combine(directory, ExtensionMethods.SafeFileName(file.BlobName) + file.BlobExtension);
                if (File.Exists(fileName))
                {
                    try
                    {
                        File.Delete(fileName);
                    }
                    catch (Exception ex)
                    {
                        return(new CheckResult(ex));
                    }
                }

                try
                {
                    File.WriteAllBytes(fileName, file.BlobData);
                    ProcessStartInfo info = new ProcessStartInfo(fileName);
                    info.UseShellExecute = true;
                    Process.Start(info);
                    return(res);
                }
                catch (Exception ex)
                {
                    return(new CheckResult(ex));
                }
            }
        }
Пример #19
0
        public static CheckResult ValidateSave(DSModel db, DriverModel model)
        {
            CheckResult res = new CheckResult(model);

            if (string.IsNullOrWhiteSpace(model.FirstName))
            {
                res.AddError("Please enter a First Name of the driver!", model.GetName(p => p.FirstName));
            }
            if (string.IsNullOrWhiteSpace(model.SecondName))
            {
                res.AddWarning("Missing Second Name of the driver!", model.GetName(p => p.SecondName));
            }
            if (string.IsNullOrWhiteSpace(model.LastName))
            {
                res.AddError("Please enter a Last Name of the driver!", model.GetName(p => p.LastName));
            }
            //if (model.LicenseID == 0)
            //    res.AddError("Please select a license!", model.GetName(p => p.LicenseID));
            //if (!model.LicenseExpirationDate.HasValue)
            //    res.AddError("Please enter a license expiration date", model.GetName(p => p.LicenseExpirationDate));
            if (model.PayRateOverride < 0.0m)
            {
                res.AddError("Please enter a positive number for Pay Rate Override!", model.GetName(p => p.PayRateOverride));
            }
            if (model.DriverCode != string.Empty)
            {
                var check = db.Drivers.Where(d => d.DriverCode == model.DriverCode && d.DriverID != model.DriverID).FirstOrDefault();
                if (check != null)
                {
                    res.AddError("Another driver already uses this Driver Code! Use Peek or leave blank to autogenerate!", model.GetName(p => p.DriverCode));
                }
            }
            foreach (var l in model.Locations)
            {
                if (l.LocationID == 0)
                {
                    res.AddError("Please choose a Location for hte travel pay!", "LocationID");
                }
                if (l.TravelPay == 0.0m)
                {
                    res.AddError("Please enter a positive non-zero number for Travel Pay!", "TravelPay");
                }
            }

            return(res);
        }
        public static CheckResult CheckElemIsCorrect(this IScheduleElem scheduleElem)
        {
            var res = new CheckResult();

            if (scheduleElem == null)
            {
                return(res.AddError("Null schedule elem"));
            }
            try
            {
                switch (scheduleElem.Level)
                {
                case ScheduleElemLevel.Week:
                    if (!(scheduleElem is Week))
                    {
                        res.AddError($"level week is not week level {scheduleElem.Level}, type: {scheduleElem.GetType()}");
                    }
                    if (scheduleElem.Elems == null)
                    {
                        res.AddError("null children: " + JsonConvert.SerializeObject(scheduleElem));
                    }
                    else
                    {
                        res = scheduleElem.Elems?.Aggregate(res,
                                                            (result, elem) => result + CheckElemIsCorrect(elem)) ?? res;
                        var nonUniqueDays = scheduleElem.Elems?.OfType <Day>()?.GroupBy(d => d.DayOfWeek)
                                            ?.FirstOrDefault(group => @group.Count() > 1);
                        if (nonUniqueDays != null)
                        {
                            res.AddError($"not unique days in week: {nonUniqueDays.Key}");
                        }
                    }

                    break;

                case ScheduleElemLevel.Day:
                    if (!(scheduleElem is Day))
                    {
                        res.AddError($"level day is not day: level {scheduleElem.Level}, type: {scheduleElem.GetType()}");
                    }
                    else
                    {
                        var day = (Day)scheduleElem;
                        if (day.DayOfWeek > DayOfWeek.Saturday || day.DayOfWeek < DayOfWeek.Sunday)
                        {
                            res.AddError($"unknown dayofweek: {day.DayOfWeek}");
                        }
                    }

                    if (scheduleElem.Elems == null)
                    {
                        res.AddError("null children: " + JsonConvert.SerializeObject(scheduleElem));
                    }
                    else
                    {
                        res = scheduleElem.Elems?.Aggregate(res,
                                                            (result, elem) => result + CheckElemIsCorrect(elem)) ?? res;
                        scheduleElem.Elems?.OfType <Lesson>()?.OrderBy(l => l.BeginTime).Aggregate((prev, current) =>
                        {
                            if (current.BeginTime <= prev.BeginTime &&
                                (current.IsOnEvenWeek == null || prev.IsOnEvenWeek == null ||
                                 prev.IsOnEvenWeek == current.IsOnEvenWeek))
                            {
                                res.AddError($"incompatible lessons in day {((Day)scheduleElem).DayOfWeek}:" +
                                             JsonConvert.SerializeObject(prev) +
                                             JsonConvert.SerializeObject(current));
                            }
                            return(current);
                        });
                    }

                    break;

                case ScheduleElemLevel.Lesson:
                    if (!(scheduleElem is Lesson))
                    {
                        res.AddError("level lesson is not lesson" + JsonConvert.SerializeObject(scheduleElem));
                    }
                    if (scheduleElem.Elems != null)
                    {
                        res.AddError("not null children for lesson: " +
                                     JsonConvert.SerializeObject(scheduleElem));
                    }

                    break;

                default:
                    res.AddError($"Impossible to check for such level {scheduleElem.Level}");
                    break;
                }

                return(res);
            }
            catch (Exception e)
            {
                return(res.AddExeption(e));
            }
        }