public IHttpActionResult Remove(BranchOffice office)
 {
     _uow.BranchOffice.Remove(office);
     _uow.Complete();
     return(Ok());
 }
Пример #2
0
        public bool IsNameDuplicated(BranchOffice branchOffice)
        {
            IQueryable <BranchOffice> branchOffices = _repository.FindAll(x => x.Name == branchOffice.Name && !x.IsDeleted && x.Id != branchOffice.Id);

            return(branchOffices.Count() > 0 ? true : false);
        }
        public ActionResult Add()
        {
            BranchOffice branch = new BranchOffice();

            return(View(branch));
        }
Пример #4
0
        public async Task <IHttpActionResult> DeleteService([FromUri] int serviceId)
        {
            Service service = unitOfWork.Services.Get(serviceId);

            if (service == null)
            {
                return(NotFound());
            }

            RAIdentityUser user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            if (UserManager.IsInRole(user.Id, "Manager") && !UserManager.IsInRole(user.Id, "Admin"))
            {
                if (service.Creator != user.Id)
                {
                    return(BadRequest("Access denied."));
                }
            }

            List <long> branchOfficeIds = new List <long>();

            if (service.BranchOfficces != null)
            {
                foreach (BranchOffice branchOffice in service.BranchOfficces)
                {
                    branchOfficeIds.Add(branchOffice.Id);
                    ImageHelper.DeleteImage(branchOffice.Image);
                }
            }

            List <long> vehiclesIds = new List <long>();

            if (service.Vehicles != null)
            {
                foreach (Vehicle vehicle in service.Vehicles)
                {
                    vehiclesIds.Add(vehicle.Id);
                    ImageHelper.DeleteImages(vehicle.Images);
                }
            }

            List <long> commentIds = new List <long>();

            if (service.Comments != null)
            {
                foreach (Comment comment in service.Comments)
                {
                    commentIds.Add(comment.Id);
                }
            }

            List <long> raitingIds = new List <long>();

            if (service.Ratings != null)
            {
                foreach (Rating rating in service.Ratings)
                {
                    raitingIds.Add(rating.Id);
                }
            }

            ImageHelper.DeleteImage(service.LogoImage);

            try
            {
                lock (lockObjectForServices)
                {
                    foreach (long branchOfficeId in branchOfficeIds)
                    {
                        BranchOffice branchOffice = unitOfWork.BranchOffices.Get(branchOfficeId);
                        unitOfWork.BranchOffices.Remove(branchOffice);
                    }

                    foreach (long vehicleId in vehiclesIds)
                    {
                        Vehicle vehicle = unitOfWork.Vehicles.Get(vehicleId);
                        unitOfWork.Vehicles.Remove(vehicle);
                    }

                    foreach (long commentId in commentIds)
                    {
                        Comment comment = unitOfWork.Comments.Get(commentId);
                        unitOfWork.Comments.Remove(comment);
                    }

                    foreach (long raitingId in raitingIds)
                    {
                        Rating raiting = unitOfWork.Ratings.Get(raitingId);
                        unitOfWork.Ratings.Remove(raiting);
                    }

                    unitOfWork.Services.Remove(service);
                    unitOfWork.Complete();
                }
            }
            catch (DBConcurrencyException)
            {
                if (!ServiceExists(service.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok("Service successfully deleted."));
        }
Пример #5
0
 public BranchOffice UpdateObject(BranchOffice branchOffice, ICompanyInfoService _companyInfoService)
 {
     //branchOffice.Errors.Clear();
     return(branchOffice = _validator.ValidUpdateObject(branchOffice, this, _companyInfoService) ? _repository.UpdateObject(branchOffice) : branchOffice);
 }
Пример #6
0
        /**
         * Modelo "Complemento de pago"
         * - Se especifica: la moneda, método de pago, forma de pago, cliente, y lugar de expedición
         */
        private static Facturama.Models.Request.Cfdi CreateModelCfdiPaymentComplement(FacturamaApi facturama, Facturama.Models.Response.Cfdi cfdiInicial)
        {
            Cfdi cfdi = new Cfdi();

            // Lista del catálogo de nombres en el PDF
            var nameForPdf = facturama.Catalogs.NameIds.First(m => m.Value == "14"); // Nombre en el pdf: "Complemento de pago"

            cfdi.NameId = nameForPdf.Value;

            // Receptor de comprobante (se toma como cliente el mismo a quien se emitió el CFDI Inicial),
            String clientRfc = cfdiInicial.Receiver.Rfc;
            Client client    = facturama.Clients.List().Where(p => p.Rfc.Equals(clientRfc)).First();

            Receiver receiver = new Receiver
            {
                CfdiUse = "P01",
                Name    = client.Name,
                Rfc     = client.Rfc
            };

            cfdi.Receiver = receiver;

            // Lugar de expedición (es necesario por lo menos tener una sucursal)
            BranchOffice branchOffice = facturama.BranchOffices.List().First();

            cfdi.ExpeditionPlace = "78240";

            // Fecha y hora de expecidión del comprobante
            //DateTime bindingDate;
            //DateTime.TryParse(cfdiBinding.Date, null, DateTimeStyles.RoundtripKind, out bindingDate);

            cfdi.Date     = null; // Puedes especificar una fecha por ejemplo:  DateTime.Now
            cfdi.CfdiType = CfdiType.Pago;
            // Complemento de pago ---
            Complement complement = new Complement();

            // Pueden representarse más de un pago en un solo CFDI
            List <Facturama.Models.Complements.Payment> lstPagos = new List <Facturama.Models.Complements.Payment>();

            Facturama.Models.Complements.Payment pago = new Facturama.Models.Complements.Payment();

            // Fecha y hora en que se registró el pago en el formato: "yyyy-MM-ddTHH:mm:ss"
            // (la fecha del pago debe ser menor que la fecha en que se emite el CFDI)
            // Para este ejemplo, se considera que  el pago se realizó hace una hora
            pago.Date = DateTime.Now.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");


            // Forma de pago (Efectivo, Tarjeta, etc)
            Facturama.Models.Response.Catalogs.CatalogViewModel paymentForm = facturama.Catalogs.PaymentForms.Where(p => p.Name.Equals("Efectivo")).First();
            pago.PaymentForm = paymentForm.Value;

            // Selección de la moneda del catálogo
            // La Moneda, puede ser diferente a la del documento inicial
            // (En el caso de que sea diferente, se debe colocar el tipo de cambio)
            List <CurrencyCatalog> lstCurrencies = facturama.Catalogs.Currencies.ToList();
            CurrencyCatalog        currency      = lstCurrencies.Where(p => p.Value.Equals("MXN")).First();

            pago.Currency = currency.Value;

            // Monto del pago
            // Este monto se puede distribuir entre los documentos relacionados al pago
            pago.Amount = 100.00m;

            // Documentos relacionados con el pago
            // En este ejemplo, los datos se obtiene el cfdiInicial, pero puedes colocar solo los datos
            // aun sin tener el "Objeto" del cfdi Inicial, ya que los valores son del tipo "String"
            List <Facturama.Models.Complements.RelatedDocument> lstRelatedDocuments = new List <Facturama.Models.Complements.RelatedDocument>();

            Facturama.Models.Complements.RelatedDocument relatedDocument = new Facturama.Models.Complements.RelatedDocument
            {
                Uuid                  = cfdiInicial.Complement.TaxStamp.Uuid, // "27568D31-E579-442F-BA77-798CBF30BD7D"
                Serie                 = "A",                                  //cfdiInicial.Serie, // "EA"
                Folio                 = cfdiInicial.Folio,                    // 34853
                Currency              = currency.Value,
                PaymentMethod         = "PUE",                                // En el complemento de pago tiene que ser PUE
                PartialityNumber      = 1,
                PreviousBalanceAmount = 100.00m,
                AmountPaid            = 100.00m
            };
            lstRelatedDocuments.Add(relatedDocument);

            pago.RelatedDocuments = lstRelatedDocuments;

            lstPagos.Add(pago);

            complement.Payments = lstPagos;

            cfdi.Complement = complement;


            return(cfdi);
        }
Пример #7
0
 public bool ValidUpdateObject(BranchOffice branchOffice, IBranchOfficeService _branchOfficeService, ICompanyInfoService _companyInfoService)
 {
     // branchOffice.Errors.Clear();
     return(ValidCreateObject(branchOffice, _branchOfficeService, _companyInfoService));
 }
Пример #8
0
        void BranchOffice_validation()
        {
            it["validates_branchoffice"] = () =>
            {
                d.branch1.Errors.Count().should_be(0);
            };

            it["branchoffice_with_no_code"] = () =>
            {
                BranchOffice obj = new BranchOffice()
                {
                    Name        = "no code",
                    Address     = "address",
                    PhoneNumber = "phone",
                    Email       = "email",
                };
                obj = d._branchOfficeService.CreateObject(obj, d._companyInfoService);
                obj.Errors.Count().should_not_be(0);
            };

            it["branchoffice_with_same_code"] = () =>
            {
                BranchOffice obj = new BranchOffice()
                {
                    Code        = d.branch1.Code,
                    Name        = "same code",
                    Address     = "address",
                    PhoneNumber = "phone",
                    Email       = "email",
                };
                obj = d._branchOfficeService.CreateObject(obj, d._companyInfoService);
                obj.Errors.Count().should_not_be(0);
            };

            it["branchoffice_with_no_name"] = () =>
            {
                BranchOffice obj = new BranchOffice()
                {
                    Code        = "no_name",
                    Address     = "address",
                    PhoneNumber = "phone",
                    Email       = "email",
                };
                obj = d._branchOfficeService.CreateObject(obj, d._companyInfoService);
                obj.Errors.Count().should_not_be(0);
            };

            it["branchoffice_with_no_address"] = () =>
            {
                BranchOffice obj = new BranchOffice()
                {
                    Code        = "code",
                    Name        = "no address",
                    PhoneNumber = "phone",
                    Email       = "email",
                };
                obj = d._branchOfficeService.CreateObject(obj, d._companyInfoService);
                obj.Errors.Count().should_not_be(0);
            };

            it["branchoffice_with_no_phone"] = () =>
            {
                BranchOffice obj = new BranchOffice()
                {
                    Code    = "code",
                    Name    = "no phone",
                    Address = "address",
                    Email   = "email",
                };
                obj = d._branchOfficeService.CreateObject(obj, d._companyInfoService);
                obj.Errors.Count().should_not_be(0);
            };

            it["branchoffice_with_no_email"] = () =>
            {
                BranchOffice obj = new BranchOffice()
                {
                    Code        = "code",
                    Name        = "no email",
                    PhoneNumber = "phone",
                    Address     = "address",
                };
                obj = d._branchOfficeService.CreateObject(obj, d._companyInfoService);
                obj.Errors.Count().should_not_be(0);
            };

            it["update_branchoffice_with_no_code"] = () =>
            {
                d.branch1.Code = "";
                d._branchOfficeService.UpdateObject(d.branch1, d._companyInfoService);
                d.branch1.Errors.Count().should_not_be(0);
            };

            it["delete_branchoffice_having_departments"] = () =>
            {
                d._branchOfficeService.SoftDeleteObject(d.branch1, d._departmentService);
                d.branch1.Errors.Count().should_not_be(0);
            };
        }
Пример #9
0
        protected override void Seed(RentApp.Persistance.RADBContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.

            //context.People.AddOrUpdate(
            //  p => p.FullName,
            //  new Person { FullName = "Andrew Peters" },
            //  new Person { FullName = "Brice Lambson" },
            //  new Person { FullName = "Rowan Miller" }
            //);

            if (!context.Roles.Any(r => r.Name == "Admin"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Admin"
                };

                manager.Create(role);
            }

            if (!context.Roles.Any(r => r.Name == "Manager"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Manager"
                };

                manager.Create(role);
            }

            if (!context.Roles.Any(r => r.Name == "AppUser"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "AppUser"
                };

                manager.Create(role);
            }

            var userStore   = new UserStore <RAIdentityUser>(context);
            var userManager = new UserManager <RAIdentityUser>(userStore);

            if (!context.Users.Any(u => u.UserName == "*****@*****.**"))
            {
                var user = new RAIdentityUser()
                {
                    UserName = "******", Email = "*****@*****.**", EmailConfirmed = true, PasswordHash = RAIdentityUser.HashPassword("Branja95"), FirstName = "Branko", LastName = "Jelic", DateOfBirth = DateTime.Parse("07.09.1995"), IsApproved = true
                };
                userManager.Create(user);
                userManager.AddToRole(user.Id, "Admin");
            }

            if (!context.Users.Any(u => u.UserName == "*****@*****.**"))
            {
                var user = new RAIdentityUser()
                {
                    UserName = "******", Email = "*****@*****.**", EmailConfirmed = true, PasswordHash = RAIdentityUser.HashPassword("David95"), FirstName = "David", LastName = "Djekic", DateOfBirth = DateTime.Parse("02.06.1995"), IsApproved = true
                };
                userManager.Create(user);
                userManager.AddToRole(user.Id, "Admin");
            }

            context.SaveChanges();

            Service servicePS = new Service()
            {
                Creator = context.Users.SingleOrDefault(u => u.UserName == "*****@*****.**").Id, Name = "Posavinski Rent a Car", LogoImage = "", EmailAddress = "*****@*****.**", Description = "Prvi Posavinski Renta a car!", BranchOfficces = new System.Collections.Generic.List <BranchOffice>(), Vehicles = new System.Collections.Generic.List <Vehicle>(), Comments = new System.Collections.Generic.List <Comment>(), Ratings = new System.Collections.Generic.List <Rating>(), IsApproved = true
            };
            Service serviceSR = new Service()
            {
                Creator = context.Users.SingleOrDefault(u => u.UserName == "*****@*****.**").Id, Name = "Sremski Rent a Car", LogoImage = "", EmailAddress = "*****@*****.**", Description = "Prvi Sremski Renta a car!", BranchOfficces = new System.Collections.Generic.List <BranchOffice>(), Vehicles = new System.Collections.Generic.List <Vehicle>(), Comments = new System.Collections.Generic.List <Comment>(), Ratings = new System.Collections.Generic.List <Rating>(), IsApproved = true
            };

            BranchOffice branchOfficeGR = new BranchOffice()
            {
                Address = "Partizanska 2", Image = "", Latitude = 0, Longitude = 0
            };
            BranchOffice branchOfficeSB = new BranchOffice()
            {
                Address = "Heroja Davida 3", Image = "", Latitude = 0, Longitude = 0
            };

            VehicleType vehicleTypeL = new VehicleType()
            {
                TypeName = "Limuzina"
            };
            VehicleType vehicleTypeH = new VehicleType()
            {
                TypeName = "Hecbek"
            };

            Vehicle vehicleG = new Vehicle()
            {
                Model = "Golf 2", Manufactor = "WV", VehicleType = vehicleTypeL, YearMade = DateTime.Parse("01.02.1990"), Description = "Vrhunsko auto!", PricePerHour = 1.2, Images = "", IsAvailable = true
            };
            Vehicle vehicleZ = new Vehicle()
            {
                Model = "750", Manufactor = "Zastava", VehicleType = vehicleTypeH, YearMade = DateTime.Parse("01.02.1975"), Description = "Nacionalna klasa!", PricePerHour = 2.1, Images = "", IsAvailable = true
            };

            Comment comment1 = new Comment()
            {
                UserId = context.Users.SingleOrDefault(u => u.UserName == "*****@*****.**").Id, DateTime = DateTime.Now, Text = "Poz iz Grabova."
            };
            Comment comment2 = new Comment()
            {
                UserId = context.Users.SingleOrDefault(u => u.UserName == "*****@*****.**").Id, DateTime = DateTime.Now, Text = "Poz iz Srpskog Broda."
            };

            Rating rating1 = new Rating()
            {
                UserId = context.Users.SingleOrDefault(u => u.UserName == "*****@*****.**").Id, Value = 5
            };
            Rating rating2 = new Rating()
            {
                UserId = context.Users.SingleOrDefault(u => u.UserName == "*****@*****.**").Id, Value = 5
            };

            servicePS.BranchOfficces.Add(branchOfficeSB);
            servicePS.Vehicles.Add(vehicleG);
            servicePS.Comments.Add(comment1);
            servicePS.Ratings.Add(rating1);

            serviceSR.BranchOfficces.Add(branchOfficeGR);
            serviceSR.Vehicles.Add(vehicleZ);
            serviceSR.Comments.Add(comment2);
            serviceSR.Ratings.Add(rating2);

            context.BranchOffices.AddOrUpdate(branchOfficeGR);
            context.BranchOffices.AddOrUpdate(branchOfficeSB);

            context.VehicleTypes.AddOrUpdate(vehicleTypeH);
            context.VehicleTypes.AddOrUpdate(vehicleTypeL);

            context.Vehicles.AddOrUpdate(vehicleG);
            context.Vehicles.AddOrUpdate(vehicleZ);

            context.Comments.AddOrUpdate(comment1);
            context.Comments.AddOrUpdate(comment2);

            context.Ratings.AddOrUpdate(rating1);
            context.Ratings.AddOrUpdate(rating2);

            context.Services.AddOrUpdate(servicePS);
            context.Services.AddOrUpdate(serviceSR);

            context.SaveChanges();
        }
        public async Task <IActionResult> FinalCalc(decimal PricePaidFromMagdy, decimal driversTotal, decimal PricePaidForFathallah,
                                                    decimal PaidFathallahSalary, decimal totalOfIncome, decimal totalSarhas, decimal totalOfDailyExpense, decimal FinalTotal,
                                                    string InternalMerchant, string InternalMerchantPrice, string ToLeaderBoatName, string ToLeaderPrice, string BoatNameForHalek,
                                                    string HalekPrice, string HalekName, string Adding, string AddingPrice, string BoatNameExpenses, string ExpensePricee,
                                                    string OperatorName, string OperatorPrice, string Cause)
        {
            var     c = _context.Collectings.ToList().Where(x => x.Date.ToShortDateString() == TimeNow().ToShortDateString()).FirstOrDefault();
            decimal collectedToday = 0.0m;

            if (c != null)
            {
                collectedToday = (c.TotalPaidFromMerchants + c.TotalOfCashes) - (c.TotalPaidForMerchants + c.TotalHalek + c.TotalOfAdditionalPayment + c.TotalForFahAllah + c.TotalOfExpenses);
            }
            BranchOffice branch = new BranchOffice()
            {
                Date            = TimeNow(),
                Collecting      = collectedToday,
                DriversSalary   = driversTotal,
                ExpensesTotal   = totalOfDailyExpense,
                FathallahSalary = PaidFathallahSalary,
                OfficeMoney     = PricePaidFromMagdy,
                SarhasTotal     = totalSarhas,
                CurrentCredit   = FinalTotal,
                IncomeTotal     = totalOfIncome
            };

            _context.BranchOffices.Add(branch);
            _context.SaveChanges();
            var user = await _userManager.GetUserAsync(User);

            var roles = await _userManager.GetRolesAsync(user);

            int PID = 1;

            if (roles.Contains("partner"))
            {
                PID = 2;
            }
            if (InternalMerchant != null && InternalMerchantPrice != null)
            {
                var       InternalMerchantCookie      = InternalMerchant.TrimEnd(InternalMerchant[InternalMerchant.Length - 1]);
                var       InternalMerchantPriceCookie = InternalMerchantPrice.TrimEnd(InternalMerchantPrice[InternalMerchantPrice.Length - 1]);
                string[]  InternalMerchantNames       = InternalMerchantCookie.Split(",").Select(c => Convert.ToString(c)).ToArray();
                decimal[] InternalMerchantprices      = InternalMerchantPriceCookie.Split(",").Select(c => Convert.ToDecimal(c)).ToArray();

                for (int i = 0; i < InternalMerchantNames.Length; i++)
                {
                    var             merchant = _context.Merchants.FirstOrDefault(c => c.MerchantName == InternalMerchantNames[i]);
                    PaidForMerchant m;
                    m = new PaidForMerchant()
                    {
                        IsPaidForUs = true,
                        MerchantID  = merchant.MerchantID,
                        Payment     = InternalMerchantprices[i],
                        PreviousDebtsForMerchant = merchant.PreviousDebts - InternalMerchantprices[i],
                        Date     = TimeNow(),
                        IsCash   = true,
                        PersonID = PID
                    };

                    //Person pppp = _context.People.Find(PID);
                    //pppp.credit += InternalMerchantprices[i];
                    merchant.PreviousDebts = merchant.PreviousDebts - InternalMerchantprices[i];
                    _context.PaidForMerchant.Add(m);
                    _context.SaveChanges();
                }
            }

            if (ToLeaderBoatName != null && ToLeaderPrice != null)
            {
                var ToLeaderCookie = ToLeaderBoatName.TrimEnd(ToLeaderBoatName[ToLeaderBoatName.Length - 1]);
                var ToPriceCookie  = ToLeaderPrice.TrimEnd(ToLeaderPrice[ToLeaderPrice.Length - 1]);

                string[]  ToLeaderBoatNames = ToLeaderCookie.Split(",").Select(c => Convert.ToString(c)).ToArray();
                decimal[] Toprices          = ToPriceCookie.Split(",").Select(c => Convert.ToDecimal(c)).ToArray();

                for (int i = 0; i < ToLeaderBoatNames.Length; i++)
                {
                    var Boat = _context.Boats.Where(c => c.BoatName == ToLeaderBoatNames[i]).FirstOrDefault();
                    _context.LeaderLoans.Add(new LeaderLoan {
                        Price = Toprices[i], BoatID = Boat.BoatID, Date = TimeNow(), PersonID = PID
                    });
                    Boat.DebtsOfLeader += Toprices[i];
                    //pp.credit -= Toprices[i];
                    _context.SaveChanges();
                }
            }

            if (HalekName != null)
            {
                var       BoatNameCookie   = BoatNameForHalek.TrimEnd(BoatNameForHalek[BoatNameForHalek.Length - 1]);
                var       HalekPriceCookie = HalekPrice.TrimEnd(HalekPrice[HalekPrice.Length - 1]);
                var       HalekNameCookie  = HalekName.TrimEnd(HalekName[HalekName.Length - 1]);
                string[]  BoatNames        = BoatNameCookie.Split(",").Select(c => Convert.ToString(c)).ToArray();
                decimal[] HalekPrices      = HalekPriceCookie.Split(",").Select(c => Convert.ToDecimal(c)).ToArray();
                string[]  HalekNames       = HalekNameCookie.Split(",").Select(c => Convert.ToString(c)).ToArray();

                for (int i = 0; i < HalekNames.Length; i++)
                {
                    var boat        = _context.Boats.FirstOrDefault(c => c.BoatName == BoatNames[i]);
                    var lastSarhaID = _context.Sarhas.Where(c => c.BoatID == boat.BoatID && c.IsFinished == false).FirstOrDefault().SarhaID;
                    var lastSarha   = _context.Sarhas.Find(lastSarhaID);

                    var debt_sarha = _context.Debts_Sarhas.Include(c => c.Debt).ToList().Where(c => c.SarhaID == lastSarhaID && c.Debt.DebtName == HalekNames[i] && c.PersonID == PID && c.Date.ToShortDateString() == TimeNow().ToShortDateString()).FirstOrDefault();
                    boat.DebtsOfHalek += HalekPrices[i];
                    if (debt_sarha != null)
                    {
                        debt_sarha.Price += HalekPrices[i];
                    }
                    else
                    {
                        var         debt = _context.Debts.Where(c => c.DebtName == HalekNames[i]).FirstOrDefault();
                        Debts_Sarha ds   = new Debts_Sarha()
                        {
                            Price = HalekPrices[i], DebtID = debt.DebtID, SarhaID = lastSarhaID, PersonID = PID, Date = TimeNow()
                        };
                        _context.Debts_Sarhas.Add(ds);
                        _context.SaveChanges();
                    }
                    //Person person1 = _context.People.Find(3);
                    //person1.credit -= HalekPrices[i];

                    _context.SaveChanges();
                }
                //c.TotalHalek = HalekPrices.Sum();
            }

            if (BoatNameExpenses != null)
            {
                var       BoatNameExpensesCookie = BoatNameExpenses.TrimEnd(BoatNameExpenses[BoatNameExpenses.Length - 1]);
                var       ExpensePriceCookie     = ExpensePricee.TrimEnd(ExpensePricee[ExpensePricee.Length - 1]);
                var       CauseCookie            = Cause.TrimEnd(Cause[Cause.Length - 1]);
                string[]  BoatNamesExpenses      = BoatNameExpensesCookie.Split(",").Select(c => Convert.ToString(c)).ToArray();
                decimal[] ExpensePrice           = ExpensePriceCookie.Split(",").Select(c => Convert.ToDecimal(c)).ToArray();
                string[]  Causes = CauseCookie.Split(",").Select(c => Convert.ToString(c)).ToArray();
                for (int i = 0; i < BoatNamesExpenses.Length; i++)
                {
                    var     boat = _context.Boats.FirstOrDefault(c => c.BoatName == BoatNamesExpenses[i]);
                    Expense ex   = new Expense()
                    {
                        BoatID   = boat.BoatID,
                        Cause    = Causes[i],
                        Date     = TimeNow(),
                        PersonID = PID,
                        Price    = ExpensePrice[i]
                    };

                    _context.Expenses.Add(ex);
                    boat.TotalOfExpenses += ExpensePrice[i];
                    await _context.SaveChangesAsync();

                    //Person person1 = _context.People.Find(3);
                    //person1.credit -= ExpensePrice[i];

                    await _context.SaveChangesAsync();
                }
            }

            var           p = _context.People.Find(4);
            FathAllahGift g = new FathAllahGift()
            {
                charge = PricePaidForFathallah, CreditBefore = p.credit, CreditAfter = PricePaidForFathallah + p.credit, Date = TimeNow(), PersonID = PID
            };

            p.credit += PricePaidForFathallah;
            //Person pp = _context.People.Find(3);
            //pp.credit -= fathallah;
            _context.FathAllahGifts.Add(g);
            //_context.Collectings.Add(c);
            await _context.SaveChangesAsync();

            if (Adding != null)
            {
                var       AddingCookie      = Adding.TrimEnd(Adding[Adding.Length - 1]);
                var       AddingPriceCookie = AddingPrice.TrimEnd(AddingPrice[AddingPrice.Length - 1]);
                string[]  AddingNames       = AddingCookie.Split(",").Select(c => Convert.ToString(c)).ToArray();
                decimal[] AddingPrices      = AddingPriceCookie.Split(",").Select(c => Convert.ToDecimal(c)).ToArray();
                //var collecting = _context.Collectings.ToList().Where(x => x.Date.ToShortDateString() == TimeNow().ToShortDateString()).FirstOrDefault();
                //collecting.TotalOfAdditionalPayment = AddingPrices.Sum();

                for (int i = 0; i < AddingNames.Length; i++)
                {
                    AdditionalForOffice ad = new AdditionalForOffice()
                    {
                        Name     = AddingNames[i],
                        Value    = AddingPrices[i],
                        PersonID = PID,
                        Date     = TimeNow()
                    };

                    _context.AdditionalForOffices.Add(ad);
                    //Person ppp = _context.People.Find(3);
                    //ppp.credit -= AddingPrices[i];
                    _context.SaveChanges();
                }
            }
            if (OperatorName != null)
            {
                var       OperatorNameCookie  = OperatorName.TrimEnd(OperatorName[OperatorName.Length - 1]);
                var       OperatorPriceCookie = OperatorPrice.TrimEnd(AddingPrice[AddingPrice.Length - 1]);
                string[]  OperatorNames       = OperatorNameCookie.Split(",").Select(c => Convert.ToString(c)).ToArray();
                decimal[] OperatorPrices      = OperatorPriceCookie.Split(",").Select(c => Convert.ToDecimal(c)).ToArray();
                //var collecting = _context.Collectings.ToList().Where(x => x.Date.ToShortDateString() == TimeNow().ToShortDateString()).FirstOrDefault();
                //collecting.TotalOfAdditionalPayment = AddingPrices.Sum();

                for (int i = 0; i < OperatorNames.Length; i++)
                {
                    var             operatorr = _context.Operators.Where(x => x.OperatorName == OperatorNames[i]).FirstOrDefault();
                    PaidForOperator pp        = new PaidForOperator()
                    {
                        OperatorID        = operatorr.OperatorID,
                        Payment           = OperatorPrices[i],
                        DebtsAfterPayment = operatorr.Credit - OperatorPrices[i],
                        PersonID          = PID,
                        Date = TimeNow()
                    };

                    _context.PaidForOperators.Add(pp);
                    //Person ppp = _context.People.Find(3);
                    //ppp.credit -= AddingPrices[i];
                    _context.SaveChanges();
                }
            }

            Person pppp = _context.People.Find(PID);

            pppp.credit = FinalTotal;
            await _context.SaveChangesAsync();

            return(Json(new { message = "success" }));
        }
 public static void SetBranchOffice(BranchOffice branchOff) => branchOffice = branchOff;
Пример #12
0
        public bool isValid(BranchOffice obj)
        {
            bool isValid = !obj.Errors.Any();

            return(isValid);
        }
Пример #13
0
 public bool ValidDeleteObject(BranchOffice branchOffice, IDepartmentService _departmentService)
 {
     branchOffice.Errors.Clear();
     VDontHaveDepartments(branchOffice, _departmentService);
     return(isValid(branchOffice));
 }
 public IHttpActionResult Update(BranchOffice office)
 {
     _uow.BranchOffice.Update(office);
     _uow.Complete();
     return(Ok(office));
 }
Пример #15
0
        protected override void Seed(RentApp.Persistance.RADBContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //

            Service ser = new Service
            {
                Name        = "N1",
                LogoUrl     = "",
                Email       = "E1",
                Description = "D1",
                Aproved     = true
            };

            context.Services.AddOrUpdate(ser);

            BranchOffice bo1 = new BranchOffice
            {
                ImageUrl  = "",
                Adress    = "A1",
                Longitude = 22,
                Latitude  = 33
            };

            context.BrancheOffices.AddOrUpdate(bo1);

            Vehicle v1 = new Vehicle
            {
                PricePerHour     = 333,
                Model            = "M1",
                Producer         = "P1",
                YearOfProduction = 2000,
                Description      = "D1",
                ImageUrl         = ""
            };

            context.Vehicles.AddOrUpdate(v1);

            BranchOffice bo2 = new BranchOffice
            {
                ImageUrl  = "",
                Adress    = "A2",
                Longitude = 12,
                Latitude  = 23
            };

            context.BrancheOffices.AddOrUpdate(bo2);

            Vehicle v2 = new Vehicle
            {
                PricePerHour     = 332,
                Model            = "M2",
                Producer         = "P2",
                YearOfProduction = 2001,
                Description      = "D2",
                ImageUrl         = ""
            };

            context.Vehicles.AddOrUpdate(v2);

            ser.BranchOffices = new System.Collections.Generic.List <BranchOffice>();
            ser.BranchOffices.Add(bo1);
            ser.BranchOffices.Add(bo2);

            bo1.Vehicles = new System.Collections.Generic.List <Vehicle>();
            bo1.Vehicles.Add(v1);

            bo2.Vehicles = new System.Collections.Generic.List <Vehicle>();
            bo2.Vehicles.Add(v2);

            User user1 = new User();

            user1.Approved = true;
            user1.Email    = "asd";
            user1.Password = "******";
            user1.Role     = "Client";


            context._Users.Add(user1);

            User user2 = new User();

            user2.Approved = true;
            user2.Email    = "qwe";
            user2.Password = "******";
            user2.Role     = "Manager";


            context._Users.Add(user2);


            User user3 = new User();

            user3.Approved = true;
            user3.Email    = "zxc";
            user3.Password = "******";
            user3.Role     = "Admin";


            context._Users.Add(user3);



            context.SaveChanges();
        }
 public IHttpActionResult AddBranchOfficeToService(int id, BranchOffice office)
 {
     uow.Services.AddNewBranchOffice(id, office);
     return(Ok(office.Id));
 }
Пример #17
0
 public void SetTextValues(BranchOffice branchOffice)
 {
     txtID.text      = branchOffice.iD;
     txtCity.text    = branchOffice.City;
     txtAddress.text = branchOffice.Address;
 }
Пример #18
0
 public void addBranchOffice(BranchOffice br)
 {
     dal.branchofficeDAO.addBranchOffice(br);
 }
Пример #19
0
 public void SetBranchOffice(BranchOffice branchOffice) => CurrentOffice = branchOffice;
Пример #20
0
        public void addReservation(Customer customer, BranchOffice pickUpOffice, DateTime pickupDate, BranchOffice returnOffice, DateTime returnDate, Category cat, IEnumerable <String> drivers)
        {
            Person p;

            //Remove Person object if it already exists and it is not a customer yet
            //This is the case when we create a Customer from an already existing person
            //Entity framework does not support dynamic inheritance and inheritance object migration
            p = dal.personDAO.findPersonByDni(customer.dni);
            Customer c = dal.customerDAO.findCustomerByDni(customer.dni);

            //It is a person but it is not yet a Customer in the database
            if ((p != null) && (c == null))
            {
                //Implementing Person -> Customer inheritance Migration
                foreach (Reservation r in p.DrivenReservations)
                {
                    customer.DrivenReservations.Add(r);
                }
                dal.personDAO.removePerson(p);
            }

            Reservation res = new Reservation(customer, pickUpOffice, pickupDate, returnOffice, returnDate, cat);

            //Updating Branch Offices
            pickUpOffice.PickUpReservations.Add(res);
            returnOffice.ReturnReservations.Add(res);

            //Adding Drivers

            foreach (String dni in drivers)
            {
                //Many to Many relationship

                p = dal.personDAO.findPersonByDni(dni);
                //This verification is not to add the customer as a driver twice
                //because Customer already added as a driver in Reservation constructor
                //p is null if a new customer has been added for this reservation
                //because in this case the customer is not in the DB yet
                if (p != null)
                {
                    if (p.dni != res.Customer.dni)
                    {
                        res.Drivers.Add(p);
                        p.DrivenReservations.Add(res);
                    }
                }
            }



            //Adding reservation to DB
            dal.reservationDAO.addReservation(res);
        }
Пример #21
0
 public bool isValid(BranchOffice obj)
 {
     // bool isValid = !obj.Errors.Any();
     return(true);
 }
Пример #22
0
        public JsonResult GetBranchOfficeById(int id)
        {
            BranchOffice branchOffice = branchOfficeManager.GetById(id);

            return(Json(branchOffice, JsonRequestBehavior.AllowGet));
        }
Пример #23
0
        protected override void Seed(RentApp.Persistance.RADBContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
            if (!context.Roles.Any(r => r.Name == "Admin"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Admin"
                };

                manager.Create(role);
            }

            if (!context.Roles.Any(r => r.Name == "Manager"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Manager"
                };

                manager.Create(role);
            }

            if (!context.Roles.Any(r => r.Name == "AppUser"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "AppUser"
                };

                manager.Create(role);
            }

            context.AppUsers.AddOrUpdate(

                u => u.FullName,

                new AppUser()
            {
                FullName = "Admin Adminovic"
            }

                );

            context.AppUsers.AddOrUpdate(

                p => p.FullName,

                new AppUser()
            {
                FullName = "AppUser AppUserovic"
            }

                );

            context.SaveChanges();

            var userStore   = new UserStore <RAIdentityUser>(context);
            var userManager = new UserManager <RAIdentityUser>(userStore);

            if (!context.Users.Any(u => u.UserName == "admin"))
            {
                var _appUser = context.AppUsers.FirstOrDefault(a => a.FullName == "Admin Adminovic");
                var user     = new RAIdentityUser()
                {
                    Id = "admin", UserName = "******", Email = "*****@*****.**", PasswordHash = RAIdentityUser.HashPassword("admin"), AppUserId = _appUser.Id
                };
                userManager.Create(user);
                userManager.AddToRole(user.Id, "Admin");
            }

            if (!context.Users.Any(u => u.UserName == "appu"))

            {
                var _appUser = context.AppUsers.FirstOrDefault(a => a.FullName == "AppUser AppUserovic");
                var user     = new RAIdentityUser()
                {
                    Id = "appu", UserName = "******", Email = "*****@*****.**", PasswordHash = RAIdentityUser.HashPassword("appu"), AppUserId = _appUser.Id
                };
                userManager.Create(user);
                userManager.AddToRole(user.Id, "AppUser");
            }

            Service      ser = new Service();
            BranchOffice br  = new BranchOffice();
            Vehicle      v   = new Vehicle();

            ser.Name        = "Service 1";
            ser.Email       = "*****@*****.**";
            ser.Description = "ser_1_decs";
            ser.AppUserId   = 2;

            context.Services.AddOrUpdate(
                s => s.Name,

                ser

                );
            context.SaveChanges();

            v.TypeVehicle = "Hatchback";

            v.Producer       = "Peugeot";
            v.Model          = "307";
            v.ProductionDate = DateTime.Now;
            v.ServiceId      = ser.Id;
            v.Pirce          = 25;

            br.Addres    = "br_1_addr";
            br.X         = 555555;
            br.Y         = 666666;
            br.ServiceId = ser.Id;

            context.BranchOffices.AddOrUpdate(
                s => s.Addres,

                br

                );
            context.Vehicles.AddOrUpdate(
                s => s.Model,

                v

                );
            context.SaveChanges();
        }
Пример #24
0
 public void Create(BranchOffice branchOffice)
 {
     branchOffice.CreatedDate = _clock.Now;
     Uow.BranchOffices.Add(branchOffice);
     Uow.Commit();
 }
Пример #25
0
 public BranchOffice SoftDeleteObject(BranchOffice branchOffice, IDepartmentService _departmentService)
 {
     return(branchOffice = _validator.ValidDeleteObject(branchOffice, _departmentService) ?
                           _repository.SoftDeleteObject(branchOffice) : branchOffice);
 }
Пример #26
0
 protected Account(BranchOffice openingBranch)
 {
     _id = ObjectId.GenerateNewId();
     this.openingBranch = openingBranch;
     GameEvent.instance.UpdateClient();
 }
Пример #27
0
 public BranchOffice CreateObject(BranchOffice branchOffice, ICompanyInfoService _companyInfoService)
 {
     branchOffice.Errors = new Dictionary <String, String>();
     return(_validator.ValidCreateObject(branchOffice, this, _companyInfoService) ? _repository.CreateObject(branchOffice) : branchOffice);
 }
        public IHttpActionResult PostReservation(CreateReservationBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (unitOfWork.AccountsForApprove.Find(a => a.UserId == UserManager.FindById(User.Identity.GetUserId()).Id).Count() > 0)
            {
                return(BadRequest("Your account is not approved."));
            }

            Vehicle vehicle = unitOfWork.Vehicles.Get(model.VehicleId);

            if (vehicle == null)
            {
                return(BadRequest("Non-existent vehicle."));
            }

            if (!vehicle.IsAvailable)
            {
                return(BadRequest("Vehicle is unavailable."));
            }

            if (model.ReservationStart >= model.ReservationEnd)
            {
                BadRequest("Reservation start date and time must be greater than reservation end date and time.");
            }

            if (model.ReservationStart < DateTime.Now)
            {
                BadRequest("Reservation start date and time must be greater than current date and time.");
            }

            if (model.ReservationEnd < DateTime.Now)
            {
                BadRequest("Reservation end date and time must be greater than current date and time.");
            }

            BranchOffice rentBranchOffice = unitOfWork.BranchOffices.Get(model.RentBranchOfficeId);

            if (rentBranchOffice == null)
            {
                BadRequest("Non-existent rent branch office.");
            }


            BranchOffice returnBranchOffice = unitOfWork.BranchOffices.Get(model.ReturnBranchOfficeId);

            if (returnBranchOffice == null)
            {
                BadRequest("Non-existent return branch office.");
            }

            lock (lockObjectForReservations)
            {
                IEnumerable <Reservation> vehicleReservations = unitOfWork.Reservations.Find(r => r.Id == vehicle.Id);

                int numOfexcessiveReservations = vehicleReservations.Where(r => (r.ReservationStart <= model.ReservationStart && r.ReservationEnd >= model.ReservationEnd) || (r.ReservationStart >= model.ReservationStart && r.ReservationEnd <= model.ReservationEnd) || (r.ReservationStart <= model.ReservationStart && r.ReservationEnd <= model.ReservationEnd) || (r.ReservationStart >= model.ReservationStart && r.ReservationEnd >= model.ReservationEnd)).Count();

                if (numOfexcessiveReservations > 0)
                {
                    BadRequest("The vehicle was rented in a given period.");
                }

                RAIdentityUser user = UserManager.FindById(User.Identity.GetUserId());

                Reservation reservation = new Reservation()
                {
                    Vehicle            = vehicle,
                    UserId             = user.Id,
                    ReservationStart   = model.ReservationStart,
                    ReservationEnd     = model.ReservationEnd,
                    RentBranchOffice   = rentBranchOffice,
                    ReturnBranchOffice = returnBranchOffice
                };

                try
                {
                    unitOfWork.Reservations.Add(reservation);
                    unitOfWork.Complete();
                }
                catch (DBConcurrencyException)
                {
                    return(NotFound());
                }
            }

            return(Ok("Reservation successfully created."));
        }
        public ActionResult Show(int id)
        {
            BranchOffice branch = branchOfficeService.GetByID(id);

            return(View(branch));
        }
 public CheckingAccount(BranchOffice openingBranch) : base(openingBranch)
 {
 }