Exemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            if (!User.IsInRole("Owner") && !User.IsInRole("Admin"))
            {
                //Impedimento de o owner ver as reservas dos clientes da base de dados
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "You don't have authorization to go to webpage."));
                //--------------------------------------------------------------------
            }

            if (db.Reserves.Where(p => p.StationPostId == id).Any())
            {
                return(RedirectToAction("Index"));
            }

            StationPostsAtribuition ppp = db.StationPostsAtribuition.Where(p => p.StationPostId == id).Single();

            db.StationPostsAtribuition.Remove(ppp);

            var times = db.TimeAtribuitions.Where(o => o.StationPostId == id);

            db.TimeAtribuitions.RemoveRange(times);

            StationPost stationPost = db.StationPosts.Find(id);

            db.StationPosts.Remove(stationPost);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public ActionResult AddPost(int?id)
        {
            if (!User.IsInRole("Owner") && !User.IsInRole("Admin"))
            {
                //Impedimento de o owner ver as reservas dos clientes da base de dados
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "You don't have authorization to go to webpage."));
                //--------------------------------------------------------------------
            }

            if (id == null || id < 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Station stat = db.Stations.Find(id);

            ViewBag.Tid = id;

            ViewBag.RechargeTypeId = new SelectList(db.RechargeTypes, "RechargeTypeId", "RechargeTypeName");

            StationPost post = new StationPost()
            {
                Start   = stat.Start,
                Finnish = stat.Finnish
            };

            return(View(post));
        }
Exemplo n.º 3
0
 private bool NomePostoRepetido(StationPost s)
 {
     foreach (var aux in db.StationPosts)
     {
         if (aux.StationPostName.Equals(s.StationPostName)) // Verificar a estação!
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 4
0
        public ActionResult ReservThisPost(int?id, int?timeId, int?stationId)
        {
            if (!User.IsInRole("Client"))
            {
                //Impedimento de o owner ver as reservas dos clientes da base de dados
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "You don't have authorization to go to webpage."));
                //--------------------------------------------------------------------
            }

            ViewBag.RechargeModId = new SelectList(db.RechargeMods, "RechargeModId", "RechargeModName");
            ViewBag.StationPostId = new SelectList(db.StationPosts, "StationPostId", "StationPostName");

            ViewBag.PostId    = id;
            ViewBag.TimeId    = timeId;
            ViewBag.StationId = stationId;

            StationPost stationPost = db.StationPosts.Find(id);
            Station     station     = db.Stations.Find(stationId);

            if (stationPost == null)
            {
                return(HttpNotFound());
            }

            TimeAtribuition time     = db.TimeAtribuitions.Where(o => o.TimeDataId == timeId && o.StationPostId == id).Single();
            TimeData        timeData = db.TimeDatas.Where(o => o.Status == false && o.Time.Hour == time.TimeData.Time.Hour).Single();

            DateTime reservTime = new DateTime(
                DateTime.Now.Year,
                DateTime.Now.Month,
                DateTime.Now.Day,
                timeData.Time.Hour,
                timeData.Time.Minute,
                timeData.Time.Second
                );

            string userId = db.Users.Where(o => o.UserName.Equals(User.Identity.Name)).Single().Id;

            Reserve reserve = new Reserve()
            {
                Date          = reservTime,
                Completed     = 1,
                StationPost   = stationPost,
                StationPostId = stationPost.StationPostId,
                UserId        = userId,
                Price         = stationPost.Price
            };

            return(View(reserve));
        }
Exemplo n.º 5
0
        // GET: StationPosts/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StationPost stationPost = db.StationPosts.Find(id);

            if (stationPost == null)
            {
                return(HttpNotFound());
            }
            return(View(stationPost));
        }
Exemplo n.º 6
0
        public ActionResult Edit([Bind(Include = "StationPostId,StationPostName,RechargeTypeId,Start,Finnish,Price")] StationPost stationPost)
        {
            StationPost sst = db.StationPosts.Find(stationPost.StationPostId);


            if (ModelState.IsValid)
            {
                var times = db.TimeAtribuitions.Where(o => o.StationPostId == stationPost.StationPostId);

                db.TimeAtribuitions.RemoveRange(times);

                for (int i = 0; i < db.TimeDatas.Count() / 2; i++)
                {
                    if (i < stationPost.Start.Hour || i > stationPost.Finnish.Hour)
                    {
                        var             trueTimes = db.TimeDatas.Where(o => o.Time.Hour == i).Where(k => k.Status == false).Single();
                        TimeAtribuition ta        = new TimeAtribuition()
                        {
                            StationPostId = stationPost.StationPostId,
                            StationPost   = stationPost,
                            TimeData      = trueTimes,
                            TimeDataId    = trueTimes.TimeDataId
                        };

                        db.TimeAtribuitions.Add(ta);
                    }
                    else
                    {
                        var             trueTimes = db.TimeDatas.Where(o => o.Time.Hour == i).Where(k => k.Status == true).Single();
                        TimeAtribuition ta        = new TimeAtribuition()
                        {
                            StationPostId = stationPost.StationPostId,
                            StationPost   = stationPost,
                            TimeData      = trueTimes,
                            TimeDataId    = trueTimes.TimeDataId
                        };

                        db.TimeAtribuitions.Add(ta);
                    }
                }

                db.Entry(stationPost).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.RechargeTypeId = new SelectList(db.RechargeTypes, "RechargeTypeId", "RechargeTypeName", stationPost.RechargeTypeId);
            return(View(stationPost));
        }
Exemplo n.º 7
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StationPost stationPost = db.StationPosts.Find(id);

            if (stationPost == null)
            {
                return(HttpNotFound());
            }
            ViewBag.RechargeTypeId = new SelectList(db.RechargeTypes, "RechargeTypeId", "RechargeTypeName", stationPost.RechargeTypeId);
            return(View(stationPost));
        }
Exemplo n.º 8
0
        public ActionResult ReservThisPost([Bind(Include = "ReserveId,UserId,StationPostId,RechargeModId,Date,Price,Completed")] Reserve reserve, int?id, int?timeId, int?stationId)
        {
            if (!User.IsInRole("Client"))
            {
                //Impedimento de o owner ver as reservas dos clientes da base de dados
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "You don't have authorization to go to webpage."));
                //--------------------------------------------------------------------
            }

            if (id == null || timeId == null || stationId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            StationPost stationPost = db.StationPosts.Find(id);
            Station     station     = db.Stations.Find(stationId);

            if (stationPost == null)
            {
                return(HttpNotFound());
            }

            if (ModelState.IsValid)
            {
                string userId = db.Users.Where(o => o.UserName.Equals(User.Identity.Name)).Single().Id;

                decimal saldo = db.MoneyAtribuitions.Where(o => o.UserId.Equals(userId)).Single().Cash;

                if ((saldo - stationPost.Price) < 0)
                {
                    ModelState.AddModelError(string.Empty, "Não tem dinheiro suficiente na sua conta.");

                    ViewBag.RechargeModId = new SelectList(db.RechargeMods, "RechargeModId", "RechargeModName", reserve.RechargeModId);
                    ViewBag.StationPostId = new SelectList(db.StationPosts, "StationPostId", "StationPostName", reserve.StationPostId);

                    return(View(reserve));
                }
                else
                {
                    db.MoneyAtribuitions.Where(o => o.UserId.Equals(userId)).Single().Cash = (saldo - stationPost.Price);
                }

                TimeAtribuition time = db.TimeAtribuitions.Where(o => o.TimeDataId == timeId && o.StationPostId == id).Single();

                TimeData timeData = db.TimeDatas.Where(o => o.Status == false && o.Time.Hour == time.TimeData.Time.Hour).Single();

                db.TimeAtribuitions.Remove(time);

                TimeAtribuition ta = new TimeAtribuition()
                {
                    TimeData      = timeData,
                    TimeDataId    = timeData.TimeDataId,
                    StationPost   = stationPost,
                    StationPostId = stationPost.StationPostId
                };

                db.TimeAtribuitions.Add(ta);

                //necessário porque por alguma razão desconhecida ele não consegue passar esta informação
                reserve.StationPostId = (int)id;
                //---------------------------------------------------------------------------------------

                db.Reserves.Add(reserve);

                db.SaveChanges();
                return(RedirectToAction("Details", new { id = station.StationId }));
            }

            ViewBag.RechargeModId = new SelectList(db.RechargeMods, "RechargeModId", "RechargeModName", reserve.RechargeModId);
            ViewBag.StationPostId = new SelectList(db.StationPosts, "StationPostId", "StationPostName", reserve.StationPostId);
            return(View(reserve));
        }
Exemplo n.º 9
0
        public ActionResult AddPost(StationPost stationPost, int?StationId)
        {
            if (!User.IsInRole("Owner") && !User.IsInRole("Admin"))
            {
                //Impedimento de o owner ver as reservas dos clientes da base de dados
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "You don't have authorization to go to webpage."));
                //--------------------------------------------------------------------
            }

            if (NomePostoRepetido(stationPost))
            {
                ModelState.AddModelError("StationPostName", "Já existe um posto com este nome nesta ou noutra estação.");
                AddPost(StationId);
            }
            else
            {
                if (ModelState.IsValid)
                {
                    db.StationPosts.Add(stationPost);

                    for (int i = 0; i < db.TimeDatas.Count() / 2; i++)
                    {
                        if (i < stationPost.Start.Hour || i > stationPost.Finnish.Hour)
                        {
                            var             trueTimes = db.TimeDatas.Where(o => o.Time.Hour == i).Where(k => k.Status == false).Single();
                            TimeAtribuition ta        = new TimeAtribuition()
                            {
                                StationPostId = stationPost.StationPostId,
                                StationPost   = stationPost,
                                TimeData      = trueTimes,
                                TimeDataId    = trueTimes.TimeDataId
                            };

                            db.TimeAtribuitions.Add(ta);
                        }
                        else
                        {
                            var             trueTimes = db.TimeDatas.Where(o => o.Time.Hour == i).Where(k => k.Status == true).Single();
                            TimeAtribuition ta        = new TimeAtribuition()
                            {
                                StationPostId = stationPost.StationPostId,
                                StationPost   = stationPost,
                                TimeData      = trueTimes,
                                TimeDataId    = trueTimes.TimeDataId
                            };

                            db.TimeAtribuitions.Add(ta);
                        }
                    }

                    Station stat = db.Stations.Find(StationId);

                    StationPostsAtribuition sss = new StationPostsAtribuition()
                    {
                        Station       = stat,
                        StationId     = stat.StationId,
                        StationPost   = stationPost,
                        StationPostId = stationPost.StationPostId
                    };

                    db.StationPostsAtribuition.Add(sss);

                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }

            ViewBag.RechargeTypeId = new SelectList(db.RechargeTypes, "RechargeTypeId", "RechargeTypeName", stationPost.RechargeTypeId);
            return(View(stationPost));
        }