public ActionResult Create([Bind(Include = "ID,clientId,CategoryID,Title,Content")] Recipe recipe)
        {
            if (recipe.Content == null || recipe.Title == null || recipe.CategoryId == 0)
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (!AuthorizationMiddleware.Authorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (ModelState.IsValid)
            {
                recipe.CreationDate = DateTime.Now;
                _db.Recipes.Add(recipe);
                _db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.ClientID   = new SelectList(_db.Clients, "ID", "ClientName", recipe.ClientId);
            ViewBag.CategoryID = new SelectList(_db.Categories, "ID", "Name", recipe.CategoryId);

            return(View(recipe));
        }
        public ActionResult Create([Bind(Include = "ID,Gender,ClientName,FirstName,LastName,Password,isAdmin")] Client client)
        {
            if (!ModelState.IsValid)
            {
                return(View(client));
            }

            var requestedUser = _db.Clients.FirstOrDefault(x => x.ClientName == client.ClientName);

            if (requestedUser != null)
            {
                return(View(client));
            }

            _db.Clients.Add(client);
            _db.SaveChanges();

            return(RedirectToAction("RecipesLogin", "Clients"));
        }
예제 #3
0
        public ActionResult Create([Bind(Include = "ID,ClientID,RecipeID,Content,CreationDate")] Comment comment)
        {
            if (!AuthorizationMiddleware.Authorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (ModelState.IsValid)
            {
                _db.Comments.Add(comment);
                _db.SaveChanges();

                return(RedirectToAction("Index", "Recipes"));
            }

            ViewBag.ClientID = new SelectList(_db.Clients, "ID", "ClientName", comment.ClientId);
            ViewBag.RecipeID = new SelectList(_db.Recipes, "ID", "Content", comment.RecipeId);

            return(View(comment));
        }
예제 #4
0
        public ActionResult Create([Bind(Include = "ID,Name")] Category category)
        {
            if (!AuthorizationMiddleware.AdminAuthorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (!ModelState.IsValid)
            {
                return(View(category));
            }

            var requestedCategory = _db.Categories.FirstOrDefault(x => x.Name == category.Name);

            if (requestedCategory != null)
            {
                return(View(category));
            }

            _db.Categories.Add(category);
            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }