Esempio n. 1
0
 public ActionResult Register(Customer customer)
 {
     if (db.Customers.FirstOrDefault() != null)
     {
         var loginExists = db.Customers.Any(x => x.Login == customer.Login);
         var emailExists = db.Customers.Any(x => x.Email == customer.Email);
         if (loginExists)
         {
             ViewData["loginExistsMessage"] = "Такой логин уже занят!";
         }
         if (emailExists)
         {
             ViewData["emailExistsMessage"] = "Пользователь с таким e-mail уже зарегистрирован";
         }
         if ((loginExists == false) && (emailExists == false) && ModelState.IsValid)
         {
             customer.RoleId = 3;
             db.Customers.Add(customer);
             db.SaveChanges();
             TempData["registrationSuccess"] = "Регистрация успешна!";
             return(RedirectToAction("Login"));
         }
     }
     else
     {
         customer.RoleId = 3;
         db.Customers.Add(customer);
         db.SaveChanges();
         TempData["registrationSuccess"] = "Регистрация успешна!";
         return(RedirectToAction("Login"));
     }
     return(View());
 }
Esempio n. 2
0
        private static void RegisterOrder()
        {
            bool showMenu = true;

            WriteLine("Kund (personr.):");
            string   socialSecurityNumber = ReadLine();
            Order    order    = new Order();
            Customer customer = Context.Customer.FirstOrDefault(customer => customer.SocialSecurityNumber == socialSecurityNumber);

            while (showMenu)
            {
                if (customer != null)
                {
                    Clear();

                    WriteLine($"{customer.FirstName} {customer.LastName}, {customer.SocialSecurityNumber}");
                    WriteLine();
                    WriteLine("Artikel");
                    WriteLine("-------------------------------------------");
                    foreach (ArticleOrder articleOrder in order.Articles)
                    {
                        WriteLine(articleOrder.Article.Name);
                    }
                    WriteLine();
                    WriteLine("(L)ägg till (S)kapa order");
                    ConsoleKeyInfo keyPressed = ReadKey(true);
                    switch (keyPressed.Key)
                    {
                    case ConsoleKey.L:

                        Clear();
                        WriteLine("Art.nmr");
                        string articleNumber = ReadLine();

                        Article      article      = Context.Article.FirstOrDefault(x => x.ArticleNumber == articleNumber);
                        ArticleOrder articleOrder = new ArticleOrder(article);

                        order.Articles.Add(articleOrder);
                        showMenu = true;
                        break;

                    case ConsoleKey.S:
                        Clear();
                        customer.Order.Add(order);
                        Context.SaveChanges();
                        WriteLine("Order created");
                        Thread.Sleep(2000);
                        showMenu = false;
                        break;
                    }
                }
                else
                {
                    Clear();
                    WriteLine("Kund finns ej");
                    Thread.Sleep(2000);
                    showMenu = false;
                }
            }
        }
        public ActionResult Create([Bind(Include = "Id,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(category);
        }
        public ActionResult Create([Bind(Include = "ID_Type,TypeID_name,TypeID_Description")] TypeID typeID)
        {
            if (ModelState.IsValid)
            {
                db.TypeIDs.Add(typeID);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(typeID));
        }
        public ActionResult Create(NewsFeed newsFeed)   // было Create([Bind(Include = "Id,Name")] NewsFeed newsFeed)
        {
            if (ModelState.IsValid)
            {
                db.NewsFeeds.Add(newsFeed);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(newsFeed));
        }
Esempio n. 6
0
        public ActionResult Create([Bind(Include = "Product_ID,Product_Name,Product_Description,Product_Quantity")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }
Esempio n. 7
0
        public ActionResult Create([Bind(Include = "ID,Category,Cost,IconURL,Name")] Item item)
        {
            if (ModelState.IsValid)
            {
                db.Items.Add(item);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(item));
        }
Esempio n. 8
0
        public ActionResult Create([Bind(Include = "Client_ID,Client_Name,Client_Apellido,ID_Type,ID_Number")] Client client)
        {
            if (ModelState.IsValid)
            {
                db.Clients.Add(client);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ID_Type = new SelectList(db.TypeIDs, "ID_Type", "TypeID_name", client.ID_Type);
            return(View(client));
        }
        public ActionResult Create(News news)  // было Create([Bind(Include = "Id,NewsHeader,NewsBody,CreateDate,ModifyDate,NewsFeedId")] News news)
        {
            news.CreateDate = DateTime.Now;    // при создании новости сохраняем дату создания
            news.ModifyDate = DateTime.Now;    // при создании новости дата модификации равна дате создания
            news.NewsFeedId = 1;               // у нас по-умолчанию все новости для ленты с id=1 (используем одну ленту)
            //news.NewsFeedId = 1;                // тест для sourcetree - увидит ли изменения в этом "балыбердинском" контроллере?
            if (ModelState.IsValid)
            {
                db.News.Add(news);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            //ViewBag.NewsFeedId = new SelectList(db.NewsFeeds, "Id", "Name", news.NewsFeedId);
            return(View(news));
        }
        public ActionResult Create(Customer customer)
        {
            if (ModelState.IsValid)
            {
                if (customer.RoleId > 3 | customer.RoleId < 1)
                {
                    ViewData["RoleIdError"] = "Неверный RoleId";
                    return(View());
                }
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
Esempio n. 11
0
        public ActionResult Create(GameComment gameComment, int id)
        {
            if (User.Identity.IsAuthenticated == false)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized));
            }
            if (ModelState.IsValid)
            {
                gameComment.Customer = db.Customers.FirstOrDefault(x => x.Login == User.Identity.Name);
                gameComment.Time     = DateTime.Now;
                gameComment.Game     = db.Games.Find(id);
                db.GameComments.Add(gameComment);
                UpdateRating(id);
                db.SaveChanges();
                return(RedirectToAction("Details", "Games", new { id = gameComment.GameId }));
            }

            return(View(gameComment));
        }
Esempio n. 12
0
        public ActionResult Create(Game game, HttpPostedFileBase gamePoster)
        {
            if (ModelState.IsValid)
            {
                if (gamePoster != null && gamePoster.ContentLength > 0)
                {
                    string path = Server.MapPath("~/images/games/");
                    string pic  = Path.GetFileName(gamePoster.FileName);
                    gamePoster.SaveAs(Path.Combine(path, pic));
                    game.GamePosterUrl = Path.Combine("/images/games/", pic);
                }
                db.Games.Add(game);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", game.CategoryId);
            return(View(game));
        }
Esempio n. 13
0
        public override void CreateRole(string roleName)
        {
            Role newRole = new Role()
            {
                Name = roleName
            };
            GameShopContext db = new GameShopContext();

            db.Roles.Add(newRole);
            db.SaveChanges();
        }
Esempio n. 14
0
        public ActionResult DeleteConfirmed(int id)
        {
            Order order = db.Orders.Find(id);

            db.Orders.Remove(order);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 15
0
        private static void RegisterProduct()
        {
            Clear();

            bool customerExists = false;
            bool incorrectKey   = true;
            bool doNotExitLoop  = true;



            do
            {
                Write("artikelnr.: ");
                string productCode = ReadLine();
                Write("\nNamn: ");
                string productName = ReadLine();
                Write("\nBeskrivning: ");
                string productDescription = ReadLine();
                Write("\nPris: ");
                decimal productPrice = Convert.ToDecimal(ReadLine());



                Product product = new Product(productCode, productName, productDescription, productPrice);


                Console.WriteLine("Är detta korrekt? (J)a eller (N)ej");

                ConsoleKeyInfo inputKey;

                do
                {
                    inputKey = ReadKey(true);

                    incorrectKey = !(inputKey.Key == ConsoleKey.J || inputKey.Key == ConsoleKey.N);
                } while (incorrectKey);


                if (inputKey.Key == ConsoleKey.J)
                {
                    var customers = context.Product.FirstOrDefault(r => r.ProductCode == productCode);

                    if (customers == null)
                    {
                        context.Product.Add(product);
                        context.SaveChanges();

                        doNotExitLoop = false;
                        Clear();
                        WriteLine("Artikel registrerad");
                        Thread.Sleep(1000);
                    }
                    else if (customers != null)
                    {
                        doNotExitLoop = false;
                        Clear();
                        WriteLine("Artikelnr. redan registrerat");
                        Thread.Sleep(1000);
                    }
                }

                Clear();
            } while (doNotExitLoop);
        }