public ActionResult Edit(Category category)
        {
            if(ModelState.IsValid)
            {
                _questionRepository.SaveCategory(category);
                return RedirectToAction("List");
            }

            return View(category);
        }
        public void SaveCategory(Category category)
        {
            if (category.Id == 0)
                _container.Categories.AddObject(category);
            else if(category.EntityState == EntityState.Detached)
            {
                _container.Categories.Attach(category);
                _container.ObjectStateManager.GetObjectStateEntry(category).SetModified();
                _container.Refresh(RefreshMode.ClientWins, category);
            }

            _container.SaveChanges();
        }
        public static SubscribeViewModel CreateViewModel(Category category, string returnUrl)
        {
            var view = new SubscribeViewModel
            {
                Subscription = new Subscription
                                   {
                                       Category = category,
                                       UserName = UserModel.Current.UserName,
                                       Email = UserModel.Current.Email
                                   },
                ReturnUrl = returnUrl
            };

            return view;
        }
Example #4
0
        public void SaveCategory(Category category)
        {
            if (category.Id == 0)
            {
                _container.Categories.AddObject(category);
            }
            else if (category.EntityState == EntityState.Detached)
            {
                _container.Categories.Attach(category);
                _container.ObjectStateManager.GetObjectStateEntry(category).SetModified();
                _container.Refresh(RefreshMode.ClientWins, category);
            }

            _container.SaveChanges();
        }
        public void SendEmailFor(Category category, IEmailAssembler assembler)
        {
            var subscribers = category.Subscriptions.Select(s => s.Email).ToList();

            foreach(var subscriber in subscribers)
                SendEmail(subscriber, assembler);

            _container.SaveChanges();
        }
 /// <summary>
 /// Create a new Category object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="categoryName">Initial value of the CategoryName property.</param>
 public static Category CreateCategory(global::System.Int32 id, global::System.String categoryName)
 {
     Category category = new Category();
     category.Id = id;
     category.CategoryName = categoryName;
     return category;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Categories EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCategories(Category category)
 {
     base.AddObject("Categories", category);
 }