コード例 #1
0
        public ActionResult Add(GalleryGroupItem viewModel)
        {
            if (ModelState.IsValid)
            {
                using (var dataBase = new ApplicationDbContext())
                {
                    var existedGalleryGroups = dataBase.GalleryGroups.ToList();
                    var alreadyExistedGroup  = existedGalleryGroups.SingleOrDefault(group => group.GroupName.Equals(viewModel.GroupName, StringComparison.OrdinalIgnoreCase));
                    if (alreadyExistedGroup == null)
                    {
                        dataBase.GalleryGroups.Add(viewModel);
                        dataBase.SaveChanges();
                    }

                    existedGalleryGroups         = dataBase.GalleryGroups.ToList();
                    ViewBag.ExistedGalleryGroups = existedGalleryGroups;

                    if (alreadyExistedGroup != null)
                    {
                        //Already exist
                        return(View("AlreadyExist", alreadyExistedGroup));
                    }
                }
                ModelState.Clear();
            }

            //Successfully created
            return(View("Created", viewModel));
        }
コード例 #2
0
        // GET: /Message/Add
        public ActionResult Add()
        {
            var galleryGroupModel = new GalleryGroupItem();

            return(View(galleryGroupModel));
        }