Exemple #1
0
        public ActionResult SendMessage(int driverID, string messageText)
        {
            using (TruckTransportDbContext _db = new TruckTransportDbContext())
            {
                if (messageText != null && messageText != "")
                {
                    poruke messageDB = new poruke();

                    messageDB.vozac_id = driverID;
                    messageDB.vrijeme  = UnixTime.GetUnixTimeNow();
                    messageDB.text     = messageText;
                    messageDB.odvozaca = 0;

                    _db.poruke.Add(messageDB);
                    _db.SaveChanges();

                    return(Json(new { success = true }));
                }
                else
                {
                    return(Json(new { success = false }));
                }
            }
        }
Exemple #2
0
        public ActionResult Login(LoginVM model)
        {
            if (ModelState.IsValid)
            {
                using (TruckTransportDbContext _db = new TruckTransportDbContext())
                {
                    dispecerlogin userToFind = _db.dispecerlogin.AsNoTracking().Where(x => x.username == model.Username).SingleOrDefault();

                    if (userToFind != null && userToFind.password == model.Password)
                    {
                        Authentication.StartSession(user: userToFind, rememberMe: model.RememberMe);

                        userToFind.lastlogin = UnixTime.GetUnixTimeNow();
                        _db.SaveChanges();

                        return(RedirectToAction(actionName: "Index", controllerName: "Home"));
                    }

                    ModelState.AddModelError("", "Pogrešno korisničko ime ili lozinka!");
                }
            }

            return(View(viewName: "Login", model: model));
        }
Exemple #3
0
        public ActionResult Edit(EditOrderVM model)
        {
            if (model.TaskIDs != null && model.DriverStopIDs != null)
            {
                if (model.TaskIDs.Length > 10 || model.DriverStopIDs.Length > 10)
                {
                    ModelState.AddModelError("", "Broj zadataka i broj stajališta ne može biti veći od 10!");
                }
                else if (model.TaskAndDriverStopNumbers == null)
                {
                    ModelState.AddModelError("", "Redni brojevi za sve odabrane zadatke i stajališta nisu dodijeljeni!");
                }
                else if (model.TaskAndDriverStopNumbers != null && model.TaskIDs.Length + model.DriverStopIDs.Length > model.TaskAndDriverStopNumbers.Count)
                {
                    ModelState.AddModelError("", "Redni brojevi za sve odabrane zadatke i stajališta nisu dodijeljeni!");
                }
            }

            if (model.TaskIDs != null && model.DriverStopIDs == null)
            {
                if (model.TaskIDs.Length > 2)
                {
                    ModelState.AddModelError("", "Stajalište je obavezno ako je broj zadataka veći od 2!");
                }

                if (model.TaskAndDriverStopNumbers == null)
                {
                    ModelState.AddModelError("", "Redni brojevi za sve odabrane zadatke nisu dodijeljeni!");
                }
                else if (model.TaskIDs.Length > model.TaskAndDriverStopNumbers.Count)
                {
                    ModelState.AddModelError("", "Redni brojevi za sve odabrane zadatke nisu dodijeljeni!");
                }
            }

            //check difference between numbers in list
            if (model.TaskAndDriverStopNumbers != null)
            {
                if (model.TaskAndDriverStopNumbers.Count != 0)
                {
                    var descOrderedNumbers = model.TaskAndDriverStopNumbers.OrderByDescending(x => x.Number);

                    if (descOrderedNumbers.Last().Number != 1)
                    {
                        ModelState.AddModelError("", "Najmanji redni broj mora biti 1!");
                    }

                    int orderNumberErrorCounter = 0;

                    for (int i = 0; i < descOrderedNumbers.Count(); i++)
                    {
                        if (descOrderedNumbers.Count() > 1 && (i + 1) < descOrderedNumbers.Count())
                        {
                            int difference = descOrderedNumbers.ElementAt(i).Number - descOrderedNumbers.ElementAt(i + 1).Number;

                            if (difference != 1 && orderNumberErrorCounter == 0)
                            {
                                orderNumberErrorCounter = 1;
                                ModelState.AddModelError("", "Redni brojevi nisu ispravno raspoređeni. Razlika između dva broja mora biti 1!");
                            }
                        }
                    }
                }
            }

            if (ModelState.IsValid)
            {
                try
                {
                    using (TruckTransportDbContext _db = new TruckTransportDbContext())
                    {
                        nalozi nalogDB = _db.nalozi.Where(x => x.nalog_id == model.OrderID).FirstOrDefault();

                        nalogDB.vrijeme_kreiranja = UnixTime.GetUnixTimeNow();
                        nalogDB.vozilo_id         = model.VehicleID;
                        nalogDB.vozac_id          = model.DriverID;

                        _db.Entry(nalogDB).State = EntityState.Modified;

                        var previousTaskList = _db.zadaci.Where(x => x.nalog_id == model.OrderID).ToList();

                        if (previousTaskList != null)
                        {
                            foreach (var previousTask in previousTaskList)
                            {
                                previousTask.nalog_id         = null;
                                _db.Entry(previousTask).State = EntityState.Modified;
                            }
                        }

                        foreach (var taskID in model.TaskIDs)
                        {
                            zadaci taskDB = _db.zadaci.Where(x => x.zadatak_id == taskID).FirstOrDefault();

                            if (taskDB != null)
                            {
                                taskDB.nalog_id         = nalogDB.nalog_id;
                                taskDB.broj_zadatka     = model.TaskAndDriverStopNumbers.Where(x => x.ID == taskDB.zadatak_id && x.IsTask).FirstOrDefault().Number;
                                _db.Entry(taskDB).State = EntityState.Modified;
                            }
                        }

                        var previousDriverStops = _db.stajalista_nalozi.Where(x => x.nalog_id == model.OrderID).ToList();

                        if (previousDriverStops != null)
                        {
                            _db.stajalista_nalozi.RemoveRange(previousDriverStops);
                        }

                        if (model.DriverStopIDs != null)
                        {
                            List <stajalista_nalozi> driverStopsOrders = new List <stajalista_nalozi>();

                            foreach (var driverStopID in model.DriverStopIDs)
                            {
                                stajalista_nalozi driverStopOrderDB = new stajalista_nalozi();
                                driverStopOrderDB.stajaliste_id   = (int)driverStopID;
                                driverStopOrderDB.nalog_id        = nalogDB.nalog_id;
                                driverStopOrderDB.broj_stajalista = model.TaskAndDriverStopNumbers.Where(x => x.ID == driverStopOrderDB.stajaliste_id && !x.IsTask).FirstOrDefault().Number;
                                driverStopsOrders.Add(driverStopOrderDB);
                            }

                            _db.stajalista_nalozi.AddRange(driverStopsOrders);
                        }

                        _db.SaveChanges();

                        return(RedirectToAction(actionName: "Index"));
                    }
                }
                catch (Exception)
                {
                }
            }

            model.Drivers  = _dropdownMaker.GetDrivers();
            model.Vehicles = _dropdownMaker.GetVehicles();

            model.Tasks       = _dropdownMaker.GetUnattachedAndSpecificOrderAttachedTasks(model.OrderID);
            model.DriverStops = _dropdownMaker.GetDriverStops();

            return(View(viewName: "Edit", model: model));
        }