Exemplo n.º 1
0
 public void Begin(Order order)
 {
     order.StartDate = DateTime.Now;
     order.EndDate   = null;
     context.Orders.Add(order);
     context.SaveChanges();;
 }
Exemplo n.º 2
0
        private static void InitializeParts(WorkshopContext db, int partsNumber)
        {
            db.Database.EnsureCreated();

            //проверка, занесены ли данные в Parts
            if (db.Parts.Any())
            {
                return; //бд иницилизирована
            }

            string  partName;
            decimal price;
            string  descriptionPart;

            Random randomObj = new Random(1);

            for (int partID = 1; partID <= partsNumber; partID++)
            {
                partName        = MyRandom.RandomString(15);
                price           = randomObj.Next(5, 100);
                descriptionPart = MyRandom.RandomString(20);

                db.Parts.Add(new Part
                {
                    partName        = partName,
                    price           = price,
                    descriptionPart = descriptionPart
                });
            }

            //сохранение изменений в бд, связанную с объектом контекста
            db.SaveChanges();
        }
Exemplo n.º 3
0
        private static void InitializeBreakdowns(WorkshopContext db, int breakdownsNumber, int ordersNumber, int partsNumber, int workersNumber)
        {
            db.Database.EnsureCreated();

            //проверка, занесены ли данные в Breakdowns
            if (db.Breakdowns.Any())
            {
                return; //бд иницилизирована
            }

            int orderID;
            int partID;
            int workerID;

            Random randomObj = new Random(1);

            for (int breakdownID = 1; breakdownID <= breakdownsNumber; breakdownID++)
            {
                orderID  = db.Orders.Skip(randomObj.Next(0, db.Orders.Count() - 2)).First().orderID;
                partID   = db.Parts.Skip(randomObj.Next(0, db.Parts.Count() - 2)).First().partID;
                workerID = db.Workers.Skip(randomObj.Next(0, db.Workers.Count() - 2)).First().workerID;

                db.Breakdowns.Add(new Breakdown
                {
                    orderID  = orderID,
                    partID   = partID,
                    workerID = workerID
                });
            }

            //сохранение изменений в бд, связанную с объектом контекста
            db.SaveChanges();
        }
Exemplo n.º 4
0
        public void Save(Car car)
        {
            var changedCar = context.Cars.FirstOrDefault(c => c.Id == car.Id);

            if (changedCar != null)
            {
                changedCar.Model        = car.Model;
                changedCar.Mark         = car.Mark;
                changedCar.Registration = car.Registration;
            }
            else
            {
                context.Cars.Add(car);
            }
            context.SaveChanges();
        }
Exemplo n.º 5
0
        public IActionResult Schedule(RepairViewModel model)
        {
            if (ModelState.IsValid)
            {
                var schedule = new Schedule
                {
                    CarId      = model.Cars.CarId,
                    DateId     = model.Cars.CarId,
                    Date       = model.Schedule.Date,
                    RepairType = model.RepairType.RepairTypeName
                };

                int tableLength = _context.Schedule.ToList().Count();
                if (tableLength < 5)
                {
                    _context.Schedule.Add(schedule);
                    _context.SaveChanges();
                    TempData["Operation"] = "Repair Registration Successful.";
                    return(RedirectToAction("Index", "Home", TempData));
                }

                else
                {
                    TempData["Operation"] = "Workshop currently full, come back another day.";
                    return(RedirectToAction("Index", "Home", TempData));
                }
            }

            return(View(model));
        }
Exemplo n.º 6
0
        public void Save(Owner owner)
        {
            var changedOwner = context.Owners.FirstOrDefault(o => o.Id == owner.Id);

            if (changedOwner != null)
            {
                changedOwner.Name        = owner.Name;
                changedOwner.Surname     = owner.Surname;
                changedOwner.PhoneNumber = owner.PhoneNumber;
            }
            else
            {
                context.Owners.Add(owner);
            }
            context.SaveChanges();
        }
Exemplo n.º 7
0
        private static void InitializeWorkers(WorkshopContext db, int workersNumber, int postsNumber)
        {
            db.Database.EnsureCreated();

            //проверка, занесены ли данные в Workers
            if (db.Workers.Any())
            {
                return; //бд иницилизирована
            }

            string   fioWorker;
            int      postID;
            DateTime dateOfEmployment;
            DateTime?dateOfDismissal;
            decimal  salary;

            Random randomObj = new Random(1);

            for (int workerID = 1; workerID <= workersNumber; workerID++)
            {
                var date = new DateTime(randomObj.Next(1990, 2018),
                                        randomObj.Next(1, 12),
                                        randomObj.Next(1, 28));
                fioWorker = MyRandom.RandomString(15);
                postID    = db.Posts.Skip(randomObj.Next(0, db.Posts.Count() - 2)).First().postID;
                var twoDate = new DateTime(randomObj.Next(1, 10),
                                           randomObj.Next(1, 12),
                                           randomObj.Next(1, 28));
                if (workerID % 5 == 0)
                {
                    dateOfDismissal = date.Add(new TimeSpan(twoDate.Ticks));
                }
                else
                {
                    dateOfDismissal = null;
                }
                dateOfEmployment = date;
                salary           = randomObj.Next(100, 1000);

                db.Workers.Add(new Worker
                {
                    fioWorker        = fioWorker,
                    postID           = postID,
                    dateOfDismissal  = dateOfDismissal,
                    dateOfEmployment = dateOfEmployment,
                    salary           = salary,
                });
            }

            //сохранение изменений в бд, связанную с объектом контекста
            db.SaveChanges();
        }
        public void Save(Activity activity)
        {
            var changedActivity = context.Activities.FirstOrDefault(a => a.Id == activity.Id);

            if (changedActivity == null)
            {
                context.Activities.Add(activity);
            }
            else
            {
                throw new NotImplementedException();
            }
            context.SaveChanges();
        }
Exemplo n.º 9
0
        private static void InitializeOrders(WorkshopContext db, int ordersNumber, int carsNumber, int workersNumber)
        {
            db.Database.EnsureCreated();

            //проверка, занесены ли данные в Orders
            if (db.Orders.Any())
            {
                return; //бд иницилизирована
            }

            int      carID;
            DateTime dateReceipt;
            DateTime?dateCompletion;
            int      workerID;

            Random randomObj = new Random(DateTime.Now.Month * 30 + DateTime.Now.Year * 365 + DateTime.Now.Day
                                          + DateTime.Now.Minute);

            for (int orderID = 1; orderID <= ordersNumber; orderID++)
            {
                var date = new DateTime(randomObj.Next(1990, 2008),
                                        randomObj.Next(1, 12),
                                        randomObj.Next(1, 28));
                carID       = db.Cars.Skip(randomObj.Next(0, db.Cars.Count() - 2)).First().carID;
                dateReceipt = date;
                var twoDate = new DateTime(randomObj.Next(1, 10),
                                           randomObj.Next(1, 12),
                                           randomObj.Next(1, 28));
                if (orderID % 5 == 0)
                {
                    dateCompletion = date.Add(new TimeSpan(twoDate.Ticks));
                }
                else
                {
                    dateCompletion = null;
                }
                workerID = db.Workers.Skip(randomObj.Next(0, db.Workers.Count() - 2)).First().workerID;

                db.Orders.Add(new Order
                {
                    carID          = carID,
                    dateReceipt    = dateReceipt,
                    dateCompletion = dateCompletion,
                    workerID       = workerID
                });
            }

            //сохранение изменений в бд, связанную с объектом контекста
            db.SaveChanges();
        }
Exemplo n.º 10
0
        public void Save(Part part)
        {
            var changedPart = context.Parts.FirstOrDefault(p => p.Id == part.Id);

            if (changedPart == null)
            {
                context.Parts.Add(part);
            }
            else
            {
                throw new NotImplementedException();
            }
            context.SaveChanges();
        }
Exemplo n.º 11
0
        public async Task <IActionResult> EditBreakdown(EditBreakdownViewModel model)
        {
            try
            {
                Breakdown breakdown = await db.Breakdowns.Include("Part").Include("Worker").Include(x => x.Order).ThenInclude(x => x.Car).FirstOrDefaultAsync(t => t.breakdownID == model.Id);

                if (ModelState.IsValid)
                {
                    if (breakdown == null)
                    {
                        ErrorViewModel error = new ErrorViewModel
                        {
                            RequestId = "Ошибка! Прислана пустая модель"
                        };
                        return(View("Error", error));
                    }
                    breakdown.orderID  = model.orderID;
                    breakdown.partID   = model.partID;
                    breakdown.workerID = model.workerID;
                    db.SaveChanges();
                    return(RedirectToAction("Breakdowns", new { id = model.orderID }));
                }
                Dictionary <string, int> parts   = new Dictionary <string, int>();
                Dictionary <string, int> workers = new Dictionary <string, int>();
                Dictionary <string, int> orders  = new Dictionary <string, int>();
                foreach (var item in db.Parts)
                {
                    parts.Add(item.partName, item.partID);
                }
                foreach (var item in db.Workers)
                {
                    workers.Add(item.fioWorker, item.workerID);
                }
                foreach (var item in db.Orders.Include("Car"))
                {
                    orders.Add(item.Car.stateNumber.ToString() + " "
                               + item.dateReceipt.ToString("dd.MM.yyyy"), item.orderID);
                }
                ViewBag.parts   = parts;
                ViewBag.workers = workers;
                ViewBag.orders  = orders;
                return(View(model));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Account", "AccessDenied"));
            }
        }
Exemplo n.º 12
0
        private static void InitializeCars(WorkshopContext db, int carsNumber, int ownersNumber)
        {
            db.Database.EnsureCreated();

            //проверка, занесены ли данные в Cars
            if (db.Cars.Any())
            {
                return; //бд иницилизирована
            }

            int    ownerID;
            string model;
            int    vis;
            string colour;
            string stateNumber;
            int    yearOfIssue;
            int    bodyNumber;
            int    engineNumber;

            Random randomObj = new Random(1);

            for (int carID = 1; carID <= carsNumber; carID++)
            {
                ownerID      = db.Owners.Skip(randomObj.Next(0, db.Owners.Count() - 2)).First().ownerID;
                model        = MyRandom.RandomString(10);
                vis          = randomObj.Next(10, 100);
                colour       = MyRandom.RandomString(10);
                stateNumber  = MyRandom.RandomString(9);
                yearOfIssue  = randomObj.Next(1, 4);
                bodyNumber   = randomObj.Next(1, 10);
                engineNumber = randomObj.Next(1, 10);

                db.Cars.Add(new Car
                {
                    ownerID      = ownerID,
                    model        = model,
                    vis          = vis,
                    colour       = colour,
                    stateNumber  = stateNumber,
                    yearOfIssue  = yearOfIssue,
                    bodyNumber   = bodyNumber,
                    engineNumber = engineNumber
                });
            }

            //сохранение изменений в бд, связанную с объектом контекста
            db.SaveChanges();
        }
Exemplo n.º 13
0
        public IActionResult RegisterCar(RegisterCarViewModel model)
        {
            if (ModelState.IsValid)
            {
                var car = new Cars
                {
                    CustomerId = model.Customers.CustomerId,
                    CarId      = model.Cars.CarId
                };

                _context.Cars.Add(car);
                _context.SaveChanges();
                TempData["Operation"] = "Car Registration Successful.";
                return(RedirectToAction("Index", "Home", TempData));
            }

            return(View(model));
        }
Exemplo n.º 14
0
        public IActionResult Register(RegisterCustomerViewModel user)
        {
            if (ModelState.IsValid)
            {
                var customer = new Customers
                {
                    Firstname            = user.Firstname,
                    Lastname             = user.Lastname,
                    SocialSecurityNumber = user.SocialSecurityNumber,
                    Address = user.Address
                };

                _context.Customers.Add(customer);
                _context.SaveChanges();
                TempData["Operation"] = "Customer Registration Successful.";
                return(RedirectToAction("Index", "Home", TempData));
            }

            return(View(user));
        }
Exemplo n.º 15
0
        private static void InitializeOwners(WorkshopContext db, int ownersNumber)
        {
            db.Database.EnsureCreated();

            //проверка, занесены ли данные в Owners
            if (db.Owners.Any())
            {
                return; //бд иницилизирована
            }

            int    driverLicense;
            string fioOwner;
            string adress;
            int    phone;

            Random randomObj = new Random(1);

            for (int ownerID = 1; ownerID <= ownersNumber; ownerID++)
            {
                driverLicense = randomObj.Next(1, 3000);
                fioOwner      = MyRandom.RandomString(15);
                adress        = MyRandom.RandomString(15);
                phone         = randomObj.Next(1, 1000000);

                db.Owners.Add(new Owner
                {
                    driverLicense = driverLicense,
                    fioOwner      = fioOwner,
                    adress        = adress,
                    phone         = phone
                });
            }

            //сохранение изменений в бд, связанную с объектом контекста
            db.SaveChanges();
        }