コード例 #1
0
        public async Task <ActionResult> Register(Users model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Users user = await _db.Users.FirstOrDefaultAsync(u => u.Login == model.Login);

            if (user == null)
            {
                _db.Users.Add(model);
                var c = await _db.SaveChangesAsync();

                if (c != 1)
                {
                    ModelState.AddModelError("", "Памылка");
                    return(View(model));
                }

                FormsAuthentication.SetAuthCookie(model.Login, true);
                return(RedirectToAction("Index", "Home"));
            }

            ModelState.AddModelError("", "Ужо існуе");
            return(View(model));
        }
コード例 #2
0
        public async Task <ActionResult> Create([Bind(Include = "Id,Title,Description,Country,Genre")] Video video, HttpPostedFileBase Logo)
        {
            if (User.IsInRole("Administrator"))
            {
                if (ModelState.IsValid)
                {
                    ProcessFile(Logo, video);

                    _db.Video.Add(video);
                    await _db.SaveChangesAsync();


                    return(RedirectToAction("Index"));
                }

                return(View(video));
            }
            return(PartialView("AuthAdminError"));
        }
コード例 #3
0
        public async Task <ActionResult> Create([Bind(Include = "Id,IdVideo,IdFormat,Price,Box")] Edition edition)
        {
            if (User.IsInRole("Administrator"))
            {
                if (ModelState.IsValid)
                {
                    _db.Edition.Add(edition);
                    await _db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }

                ViewBag.IdFormat = new SelectList(_db.Format, "Id", "Container", edition.IdFormat);
                ViewBag.IdVideo  = new SelectList(_db.Video, "Id", "Title", edition.IdVideo);

                return(View(edition));
            }
            return(PartialView("AuthAdminError"));
        }
コード例 #4
0
        public async Task <ActionResult> Create([Bind(Include = "Id,Name")] Roles Roles)
        {
            if (User.IsInRole("Administrator"))
            {
                if (!ModelState.IsValid)
                {
                    return(View(Roles));
                }
                if (_db.Roles.FirstOrDefault(t => t.Name.Equals(Roles.Name)) != null)
                {
                    ModelState.AddModelError("", "Такая роля існуе");
                    return(View(Roles));
                }
                _db.Roles.Add(Roles);
                await _db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(PartialView("AuthAdminError"));
        }
コード例 #5
0
        public async Task <ActionResult> Create([Bind(Include = "Id,Container,Languages,Support3D")] Format format)
        {
            if (ModelState.IsValid)
            {
                if (
                    _db.Format.FirstOrDefault(
                        t =>
                        t.Container == format.Container && t.Languages == format.Languages &&
                        t.Support3D == format.Support3D) != null)
                {
                    ModelState.AddModelError("", "Ужо існуе");
                    return(View(format));
                }
                _db.Format.Add(format);
                await _db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(format));
        }
コード例 #6
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,IdUser,IdEdition,Date")] History history)
        {
            if (User.IsInRole("Administrator"))
            {
                if (ModelState.IsValid)
                {
                    _db.Entry(history).State = System.Data.Entity.EntityState.Modified;
                    await _db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
                ViewBag.IdEdition = new SelectList(_db.Edition, "Id", "Box", history.IdEdition);
                ViewBag.IdUser    = new SelectList(_db.Users, "Id", "Login", history.IdUser);
                return(View(history));
            }
            return(PartialView("AuthAdminError"));
        }