Ejemplo n.º 1
0
        public ActionResult Update(int id)
        {
            var currentUser = this.User.Identity.GetUserName();
            var userId      = UserManager.FindByName(currentUser).Id;
            var isAdmin     = this.UserManager.IsInRole(userId, "Admin");

            var db = new ApplicationDbContext();
            var productionUnitService = new ProductionUnitService(db);

            var currentProductionUnits = db.ProductionUnits.Include(p => p.owner.user)
                                         .Where(p => p.owner.user.UserName == currentUser &&
                                                p.Id == id).ToList();

            var currentProductionUnit = currentProductionUnits.FirstOrDefault();

            if (currentProductionUnit != null && isAdmin == false && currentProductionUnit.Id != id)
            {
                return(Redirect("/PioneerProductionSite/" + currentProductionUnit.Id));
            }

            var currentProductionUnitViewModel = productionUnitService.One(id);

            ViewBag.Options = PopulateOptions(currentProductionUnitViewModel);

            return(View(currentProductionUnitViewModel));
        }
Ejemplo n.º 2
0
        public ActionResult Update(int id)
        {
            var currentUser = this.User.Identity.GetUserName();
            var userId      = UserManager.FindByName(currentUser).Id;
            var isAdmin     = this.UserManager.IsInRole(userId, "Admin");

            var db = new ApplicationDbContext();
            var productionUnitService = new ProductionUnitService(db);

            var currentProductionUnit = db.ProductionUnits.Include(p => p.owner.user).Include(p => p.options).Where(p => p.Id == id).FirstOrDefault();

            if (currentProductionUnit != null && currentProductionUnit.owner.user.UserName == currentUser || isAdmin)
            {
                var currentProductionUnitViewModel = productionUnitService.One(id);
                return(View(currentProductionUnitViewModel));
            }

            return(Redirect("Home/Index"));
        }