コード例 #1
0
        private void createRolesAndUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();

            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));


            if (!roleManager.RoleExists("Admin"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);

                var user = new ApplicationUser();
                user.UserName       = "******";
                user.Email          = "*****@*****.**";
                user.FirstName      = "Milica";
                user.LastName       = "Despotovic";
                user.Role           = 1;
                user.NumberOfTokens = 0;

                string adminPassword = "******";

                var admin = UserManager.Create(user, adminPassword);

                if (admin.Succeeded)
                {
                    var adminAdded = UserManager.AddToRole(user.Id, "Admin");
                }
            }

            if (!roleManager.RoleExists("User"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "User";
                roleManager.Create(role);
            }

            dm150321db db = new dm150321db();

            if (!db.InformationsForAdministrator.Any())
            {
                var parameter = new InformationsForAdministrator();
                parameter.Time = 10;
                // ovo izbrisati kasnije
                parameter.ItemsPerPage = 10;
                parameter.GoldPack     = 50;
                parameter.SilverPack   = 30;
                parameter.PlatinumPack = 100;
                parameter.ValueToken   = 10;
                parameter.Currency     = "RSD";
                db.InformationsForAdministrator.Add(parameter);

                db.SaveChanges();
            }
        }
 public ActionResult Edit([Bind(Include = "ItemsPerPage,SilverPack,GoldPack,PlatinumPack,ValueToken,Time,Currency")] InformationsForAdministrator informationsForAdministrator)
 {
     log.Info("Post action Edit/InformationsForAdministratorController has been fired");
     if (ModelState.IsValid)
     {
         db.Entry(informationsForAdministrator).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(informationsForAdministrator));
 }
        public ActionResult Edit()
        {
            log.Info("Get  action Edit/InfomrationsForAdministratorController");
            InformationsForAdministrator informationsForAdministrator = db.InformationsForAdministrator.FirstOrDefault();

            if (informationsForAdministrator == null)
            {
                return(View("NotHere"));
            }
            return(View(informationsForAdministrator));
        }
        public ActionResult Edit([Bind(Include = "ItemsPerPage,SilverPack,GoldPack,PlatinumPack,ValueToken,Currency")] InformationsForAdministrator informationsForAdministrator)
        {
            log.Info("POST action /InformationsForAdministrators/Edit has been fired.");

            if (ModelState.IsValid)
            {
                db.Entry(informationsForAdministrator).State = EntityState.Modified;
                db.SaveChanges();
            }
            return(View(informationsForAdministrator));
        }
コード例 #5
0
        private void createRolesAndUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();

            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));

            if (!roleManager.RoleExists("Administrator"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Administrator";
                roleManager.Create(role);

                var user = new ApplicationUser();
                user.UserName       = "******";
                user.Email          = "*****@*****.**";
                user.FirstName      = "Tijana";
                user.LastName       = "Jovanovic";
                user.Role           = 1;
                user.NumberOfTokens = 0;

                string adminPassword = "******";

                var admin = UserManager.Create(user, adminPassword);

                if (admin.Succeeded)
                {
                    var adminAdded = UserManager.AddToRole(user.Id, "Administrator");
                }
            }
            Auctions db = new Auctions();

            if (!db.InformationsForAdministrator.Any())
            {
                var info = new InformationsForAdministrator();
                info.Currency     = "RSD";
                info.GoldPack     = 50;
                info.SilverPack   = 30;
                info.PlatinumPack = 100;
                info.ItemsPerPage = 10;
                info.ValueToken   = 10;

                db.InformationsForAdministrator.Add(info);
                db.SaveChanges();
            }


            if (!roleManager.RoleExists("RegularUser"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "RegularUser";
                roleManager.Create(role);
            }
        }
        // GET: InformationsForAdministrators/Edit/5
        public ActionResult Edit()
        {
            log.Info("GET action /InformationsForAdministrators/Edit has been fired.");

            InformationsForAdministrator informationsForAdministrator = db.InformationsForAdministrator.FirstOrDefault();

            if (informationsForAdministrator == null)
            {
                return(View("ErrorPage"));
            }
            return(View(informationsForAdministrator));
        }
コード例 #7
0
        public ActionResult Purchase(FormCollection form)
        {
            log.Info("Post /Purchase/Orders has been fire");
            InformationsForAdministrator info = db.InformationsForAdministrator.FirstOrDefault();

            if (info == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }
            ViewBag.UserId   = User.Identity.GetUserId();
            ViewBag.Silver   = info.SilverPack;
            ViewBag.Gold     = info.GoldPack;
            ViewBag.Platinum = info.PlatinumPack;


            if (form["package"] == null)
            {
                ModelState.AddModelError("packages", "You need to choose one of the packages");
                return(View());
            }

            Order order          = new Order();
            int   numberOfTokens = 0;

            if (form["package"] == "gold")
            {
                numberOfTokens = Convert.ToInt32(info.GoldPack);
            }
            else if (form["package"] == "silver")
            {
                numberOfTokens = Convert.ToInt32(info.SilverPack);
            }
            else if (form["package"] == "platinum")
            {
                numberOfTokens = Convert.ToInt32(info.PlatinumPack);
            }
            order.IdOrder        = Guid.NewGuid();
            order.NumberOfTokens = numberOfTokens;
            order.IdUser         = User.Identity.GetUserId();
            order.RealPrice      = numberOfTokens * info.ValueToken;
            order.CurrentState   = "SUBMITTED";
            db.Order.Add(order);
            db.SaveChanges();

            ViewBag.IdOrder = order.IdOrder;
            return(View("Payment"));
        }
コード例 #8
0
        public ActionResult Purchase()
        {
            log.Info("Get action /Purchase/Orders has been fired");
            InformationsForAdministrator info = db.InformationsForAdministrator.FirstOrDefault();

            if (info == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }
            ViewBag.Silver        = info.SilverPack;
            ViewBag.Gold          = info.GoldPack;
            ViewBag.Platinum      = info.PlatinumPack;
            ViewBag.UserId        = User.Identity.GetUserId();
            ViewBag.SilverValue   = info.SilverPack * info.ValueToken;
            ViewBag.GoldValue     = info.GoldPack * info.ValueToken;
            ViewBag.PlatinumValue = info.PlatinumPack * info.PlatinumPack;
            ViewBag.Currency      = info.Currency;
            return(View());
        }