Ejemplo n.º 1
0
        public ActionResult Edit([Bind(Include = "Id,FillStationId,TimeBreakId")] FillStationTimeBreak fillStationTimeBreak)
        {
            if (ModelState.IsValid)
            {
                if (ValidateFillStationTimeBreak.AlreadyExistsFillStationTimeBreak(fillStationTimeBreak))
                {
                    ModelState.AddModelError(string.Empty, "O posto já contém este intervalo.");

                    var userId       = User.Identity.GetUserId();
                    int fillstation2 = db.FillStationTimeBreaks.Find(fillStationTimeBreak.Id).FillStationId;
                    int timebreak2   = db.FillStationTimeBreaks.Find(fillStationTimeBreak.Id).TimeBreakId;
                    ViewBag.FillStationId = ListFillStationsByUserIdEdit.createListItems(db, userId, fillstation2);
                    ViewBag.TimeBreakId   = ListTimeBreakFillEdit.createListItems(db, timebreak2);

                    return(View(fillStationTimeBreak));
                }

                db.Entry(fillStationTimeBreak).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            var user        = User.Identity.GetUserId();
            int fillstation = db.FillStationTimeBreaks.Find(fillStationTimeBreak.Id).FillStationId;
            int timebreak   = db.FillStationTimeBreaks.Find(fillStationTimeBreak.Id).TimeBreakId;

            ViewBag.FillStationId = ListFillStationsByUserIdEdit.createListItems(db, user, fillstation);
            ViewBag.TimeBreakId   = ListTimeBreakFillEdit.createListItems(db, timebreak);
            return(View(fillStationTimeBreak));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FillStationTimeBreak fillStationTimeBreak = db.FillStationTimeBreaks.Find(id);

            if (fillStationTimeBreak == null)
            {
                return(HttpNotFound());
            }
            if (fillStationTimeBreak.FillStation.Station.OwnerId != User.Identity.GetUserId() && !User.IsInRole("Admin"))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
            var user        = User.Identity.GetUserId();
            int fillstation = db.FillStationTimeBreaks.Find(id).FillStationId;
            int timebreak   = db.FillStationTimeBreaks.Find(id).TimeBreakId;

            ViewBag.FillStationId = ListFillStationsByUserIdEdit.createListItems(db, user, fillstation);
            ViewBag.TimeBreakId   = ListTimeBreakFillEdit.createListItems(db, timebreak);
            return(View(fillStationTimeBreak));
        }