예제 #1
0
        public ActionResult RegisterOperator(RegisterModel model)
        {
            if(ModelState.IsValid)
            {
               if(!_db.Admins.Any(item => item.Name == model.Name))
                {
                    _db.Admins.Add(new Admin()
                    {
                        Name = model.Name,
                        LastName = model.LastName,
                        Password = model.Password,
                        AdminCategoryId = model.AdminCategoryId
                    });

                    _db.SaveChangesAsync();
                    return RedirectToAction("Index", "Home");
                }
            }

            ViewBag.AdminCategoryId = new SelectList(_db.AdminCategories, "Id", "Name");
            return View(model);
        }
        public ActionResult RegisterOperator(RegisterModel model)
        {
            if(ModelState.IsValid)
            {
               if(!_db.Operators.Any(item => item.Name == model.Name))
                {
                    _db.Operators.Add(new Operator()
                    {
                        Name = model.Name,
                        Lastname = model.LastName,
                        Password = model.Password,
                        CategoryID = model.AdminCategoryId
                    });
                   
                    _db.SaveChangesAsync();
                    return RedirectToAction("Create", "Orders");
                }
            }

            ViewBag.AdminCategoryId = new SelectList(_db.Categories, "CategoryID", "name");
            ViewData["Operators"] = _db.Operators.OrderByDescending(e => e.OperatorID).ToList();
            return View(model);
        }