public CheckResult SaveFile(FileBlobModel model)
        {
            if (!model.IsChanged)
            {
                return(new CheckResult(model));
            }

            using (DSModel db = DB.GetContext())
            {
                var check = FileBlobValidator.ValidateSave(db, model);
                if (check.Failed)
                {
                    return(check);
                }

                KeyBinder key = new KeyBinder();
                try
                {
                    FileBlobRepository.SaveBlob(db, key, model);
                    db.SaveChanges();
                    key.BindKeys();
                    model.IsChanged = false;
                    return(new CheckResult(model));
                }
                catch (Exception ex)
                {
                    key.RollbackKeys();
                    return(new CheckResult(ex));
                }
            }
        }
        public CheckResult SaveUser(UserModel user)
        {
            try
            {
                using (var db = DB.GetContext())
                {
                    var check = UserValidator.ValidateSave(db, user);
                    if (check.Failed)
                    {
                        return(check);
                    }

                    KeyBinder key = new KeyBinder();
                    UserRepository.SaveUser(db, key, user);
                    db.SaveChanges();
                    key.BindKeys();
                    user.IsChanged = false;
                    return(check);
                }
            }
            catch (Exception ex)
            {
                return(new CheckResult(ex));
            }
        }
        public CheckResult AttachMultipleFiles(string[] files)
        {
            using (var db = DB.GetContext())
            {
                KeyBinder key = new KeyBinder();
                try
                {
                    foreach (string file in files)
                    {
                        FileBlobModel mod = new FileBlobModel();
                        mod.BlobName      = Path.GetFileNameWithoutExtension(file);
                        mod.BlobExtension = Path.GetExtension(file);
                        mod.BlobData      = File.ReadAllBytes(file);
                        mod.DriverID      = this.CreationInfo.DriverID;

                        FileBlobRepository.SaveBlob(db, key, mod);
                    }

                    db.SaveChanges();
                    key.BindKeys();
                    return(new CheckResult());
                }
                catch (Exception ex)
                {
                    key.RollbackKeys();
                    return(new CheckResult(ex));
                }
            }
        }
Example #4
0
        public CheckResult Save()
        {
            var mod = this.ActiveModel;

            try
            {
                using (var db = DB.GetContext())
                {
                    var check = DriverMedicalValidator.ValidateSave(db, mod);
                    if (check.Failed)
                    {
                        return(check);
                    }

                    KeyBinder key = new KeyBinder();
                    DriverMedicalRepository.SaveMedical(db, key, mod);
                    db.SaveChanges();
                    key.BindKeys();
                    mod.IsChanged = false;
                    return(check);
                }
            }
            catch (Exception ex)
            {
                return(new CheckResult(ex));
            }
        }
Example #5
0
 public CheckResult SaveHolidays(List <HolidayModel> model)
 {
     try
     {
         using (var db = DB.GetContext())
         {
             KeyBinder key = new KeyBinder();
             HolidayRepository.SaveHolidays(db, key, model);
             db.SaveChanges();
             key.BindKeys();
             model.ForEach(f => f.IsChanged = false);
             return(new CheckResult());
         }
     }
     catch (Exception ex)
     {
         return(new CheckResult(ex));
     }
 }
Example #6
0
        public CheckResult SaveCompany(CompanyModel model, List <CompanyLicensePayRateModel> licenseRates, List <CompanyInvoicingPayRateModel> invoiceRates)
        {
            try
            {
                using (var db = DB.GetContext())
                {
                    var check = CompanyValidator.ValidateSave(db, model);
                    if (check.Failed)
                    {
                        return(check);
                    }

                    var checkLicense = CompanyValidator.ValidateDriverRates(db, licenseRates);
                    if (checkLicense.Failed)
                    {
                        return(checkLicense);
                    }

                    var checkInvoice = CompanyValidator.ValidateInvoiceRates(db, invoiceRates);
                    if (checkInvoice.Failed)
                    {
                        return(checkInvoice);
                    }

                    KeyBinder key = new KeyBinder();
                    CompanyRepository.SaveCompany(db, key, model);
                    if (model.CompanyID != 0)
                    {
                        CompanyRepository.SaveLicensesPayRates(db, key, licenseRates);
                        CompanyRepository.SaveInvoicePayRates(db, key, invoiceRates);
                    }
                    db.SaveChanges();
                    key.BindKeys();
                    model.IsChanged = false;

                    return(check);
                }
            }
            catch (Exception ex)
            {
                return(new CheckResult(ex));
            }
        }
        public void GenerateInvoices(uint[] companies, uint[] locations, DateTime periodFrom, DateTime periodTo)
        {
            Task.Run(() =>
            {
                try
                {
                    using (var db = DB.GetContext())
                    {
                        float index   = 0.0f;
                        KeyBinder key = new KeyBinder();
                        foreach (uint l in locations)
                        {
                            var loc     = LocationRepository.GetLocation(db, l);
                            var invoice = InvoiceRepository.CreateInvoice(db, loc.CompanyID, loc.LocationID, periodFrom, periodTo);
                            if (invoice.TotalAmount == 0.00m)
                            {
                                continue;
                            }

                            int percent = (int)((index / (float)locations.Length) * 100.0f);
                            RaiseProgress(percent, new ProgressItem(ProgressStatus.OK,
                                                                    string.Format("Generating invoice, Location: {0}", loc.LocationName)));

                            index++;

                            InvoiceRepository.SaveInvoice(db, key, invoice);
                        }

                        db.SaveChanges();
                        key.BindKeys();
                        RaiseComplete(new ProgressItem(ProgressStatus.OK, "Invoice generation complete!"));
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex, "InvoiceCatalogManager.GenerateInvoices()");
                    RaiseComplete(new ProgressItem(ProgressStatus.Error, ex.ToString()));
                }
            });
        }
Example #8
0
        public CheckResult Save()
        {
            var model = this.ActiveModel;

            try
            {
                using (var db = DB.GetContext())
                {
                    KeyBinder key = new KeyBinder();

                    model.Permits.Clear();
                    var permits = this.Permits
                                  .Where(p => p.IsCheck)
                                  .Select(p =>
                                          new DriverLicensePermitModel()
                    {
                        PermitID = p.Value
                    });
                    model.Permits.AddRange(permits);

                    var check = DriverLicenseValidator.ValidateSave(db, model);
                    if (check.Failed)
                    {
                        return(check);
                    }

                    DriverLicenseRepository.SaveDriverLicense(db, key, model);
                    db.SaveChanges();
                    key.BindKeys();
                    model.IsChanged = false;
                    return(check);
                }
            }
            catch (Exception ex)
            {
                return(new CheckResult(ex));
            }
        }
Example #9
0
        public CheckResult SaveInvoice(InvoiceModel model)
        {
            try
            {
                using (var db = DB.GetContext())
                {
                    var check = InvoiceValidator.ValidateSave(db, model);
                    if (check.Failed)
                    {
                        return(check);
                    }

                    KeyBinder key = new KeyBinder();
                    InvoiceRepository.SaveInvoice(db, key, model);
                    db.SaveChanges();
                    key.BindKeys();
                    return(check);
                }
            }
            catch (Exception ex)
            {
                return(new CheckResult(ex));
            }
        }