Ejemplo n.º 1
0
 public ActionResult Edit_Category(Category category)
 {
     if (ModelState.IsValid)
     {
         categoryRepository.AddOrUpdate(category);
     }
     return(RedirectToAction("Index"));
 }
        public void TestAddOrUpdate()
        {
            //add
            DateTime dtRegistration = DateTime.Now.Date.AddDays(-2).AddHours(12.50);
            User     user           = new User("Jake", 27, dtRegistration);

            userRepo.AddOrUpdate(user);
            unitOfwork.Save();
            User userInDb = userRepo.FindByName("Jake");

            Assert.AreEqual(user.Name, userInDb.Name);

            //update
            userInDb.Age = 29;
            userRepo.AddOrUpdate(userInDb);


            //add categories to db
            foreach (var item in categories)
            {
                categoryRepo.AddOrUpdate(item);
            }
            unitOfwork.Save();

            //assign the category to products and add to db
            foreach (var item in products)
            {
                if (item.Name.Contains("Sumsung"))
                {
                    item.Category = categories[1];
                }
                else
                {
                    item.Category = categories[0];
                }

                productRepo.AddOrUpdate(item);
            }
            unitOfwork.Save();

            //add products to stores
            Store rozetkaStore = stores[0];

            rozetkaStore.Products.Add(products[0]);
            rozetkaStore.Products.Add(products[2]);
            rozetkaStore.Products.Add(products[1]);

            Store mobidickStore = stores[1];

            mobidickStore.Products.Add(products[0]);
            mobidickStore.Products.Add(products[3]);
            mobidickStore.Products.Add(products[2]);

            //add stores to db
            storeRepo.AddOrUpdate(rozetkaStore);
            storeRepo.AddOrUpdate(mobidickStore);
            unitOfwork.Save();

            unitOfwork.Dispose();
        }
Ejemplo n.º 3
0
        public async Task <ViewResult <CategoryModel> > AddOrUpdate(CategoryModel model, string userName)
        {
            var result = new ViewResult <CategoryModel>();

            try
            {
                using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    //check duplicated name
                    var dupCategory = await _categoryRepository.GetCategoryByName(model.CategoryName, model.Id);

                    if (dupCategory != null)
                    {
                        result.Status  = -2;
                        result.Message = "Name is already taken";
                        return(result);
                    }
                    Category category;
                    //new uom model
                    if (model.Id == 0)
                    {
                        category = new Category()
                        {
                            CategoryName = model.CategoryName,
                            Id           = model.Id,
                            CreateBy     = userName,
                            CreateTime   = DateTime.UtcNow
                        };
                    }
                    else
                    {
                        category = await _categoryRepository.GetById(model.Id);

                        if (category == null)
                        {
                            result.Status  = -3;
                            result.Message = "Category does not exist";
                            return(result);
                        }
                        category.EditTime     = DateTime.UtcNow;
                        category.EditBy       = userName;
                        category.CategoryName = model.CategoryName;
                    }
                    await _categoryRepository.AddOrUpdate(category);

                    result.Data = category.ToCategoryModel();
                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.Status  = -1;
                result.Message = ex.Message;
                Logger.WriteErrorLog("CategoryService", "AddOrUpdate", ex);
            }
            return(result);
        }
        public ActionResult AddOrUpdate(Pyramid.Entity.Category model)
        {
            _categoryRepository.AddOrUpdate(model);
            var routeItem = new RouteItem(0, null, (string)ControllerContext.RequestContext.RouteData.Values["controller"],
                                          "Index",
                                          model.Id)
            {
                Type = Common.TypeEntityFromRouteEnum.CategoryType
            };

            _routeItemRepository.AddOrUpdate(routeItem);
            return(RedirectToAction("AdminIndex"));
        }
Ejemplo n.º 5
0
        private void btnSave_Click(object sender, System.EventArgs e)
        {
            if (string.IsNullOrEmpty(tbCategory.Text))
            {
                MessageBox.Show("Введите название категории!", "Введите данные!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (category == null)
            {
                category = new Category();
            }
            category.Name = tbCategory.Text;
            _categoryRepository.AddOrUpdate(category);
            Close();
        }
        public ActionResult AddOrUpdate(Category model)
        {
            if (ModelState.IsValid)
            {
                var cat = new Category();
                if (model.Id != 0)
                {
                    cat = cr.SelectById(model.Id);
                }
                cat.Name        = model.Name;
                cat.Description = model.Description;
                cr.AddOrUpdate(cat);

                return(RedirectToAction("List"));
            }
            return(View(model));
        }
Ejemplo n.º 7
0
        public void TestAddOrUpdateProduct()
        {
            //add categories to db
            foreach (var item in categories)
            {
                categoryRepo.AddOrUpdate(item);
            }
            categoryRepo.Save();

            //assign the category to products and add to db
            foreach (var item in products)
            {
                if (item.Name.Contains("Sumsung"))
                {
                    item.Category = categories[1];
                }
                else
                {
                    item.Category = categories[0];
                }

                productRepo.AddOrUpdate(item);
            }
            productRepo.Save();

            //add products to stores
            Store rozetkaStore = stores[0];

            rozetkaStore.Products.Add(products[0]);
            rozetkaStore.Products.Add(products[2]);
            rozetkaStore.Products.Add(products[1]);

            Store mobidickStore = stores[1];

            mobidickStore.Products.Add(products[0]);
            mobidickStore.Products.Add(products[3]);
            mobidickStore.Products.Add(products[2]);

            //add stores to db
            storeRepo.AddOrUpdate(rozetkaStore);
            storeRepo.AddOrUpdate(mobidickStore);
            storeRepo.Save();
        }
        public ActionResult Save(CategoryModel category)
        {
            if (!ModelState.IsValid)
            {
                return(View("CategoryForm", category));
            }

            try
            {
                _categoryRepo.AddOrUpdate(category);
            }
            catch (Exception e)
            {
                return(HttpNotFound());
            }
            if (category.Id == 0)
            {
                return(RedirectToAction("Index", "Category"));
            }

            return(RedirectToAction("Show", new { id = category.Id }));
        }
Ejemplo n.º 9
0
        private static void CreateCategories(StoreContext context)
        {
            var categoryRepository = new CategoryRepository(context);

            if (!categoryRepository.IsEmpty())
            {
                return;
            }

            categoryRepository.AddOrUpdate(new CategoryModel {
                DisplayOrder    = 1,
                Title           = "مدیریت دسترسی",
                Slug            = StringHelpers.Slugify("AccessManagement"),
                MetaKeywords    = "دسترسی دهی، Permission",
                MetaDescription = "توضیحات متا",
                CssClass        = "AccessManagement"
            });

            categoryRepository.AddOrUpdate(new CategoryModel {
                DisplayOrder    = 2,
                Title           = "تقویم",
                Slug            = StringHelpers.Slugify("Calendar"),
                MetaKeywords    = "تقویم, Calendar",
                MetaDescription = "توضیحات متا",
                CssClass        = "Calendar"
            });

            categoryRepository.AddOrUpdate(new CategoryModel {
                DisplayOrder    = 3,
                Title           = "برنامه نویس",
                Slug            = StringHelpers.Slugify("Developer"),
                MetaKeywords    = "برنامه نویس, توسعه، تولید, Develop, Development, Programming, Deploy, Retract, XSLT, SPWebApplication, SPSite, SPWeb, SPList, SPListItem",
                MetaDescription = "توضیحات متا",
                CssClass        = "Developer"
            });

            categoryRepository.AddOrUpdate(new CategoryModel {
                DisplayOrder    = 4,
                Title           = "مناقصات و مزایدات",
                Slug            = StringHelpers.Slugify("Tenders"),
                MetaKeywords    = "مناقصات و مزایدات, Tender, Tenders",
                MetaDescription = "توضیحات متا",
                CssClass        = "Tenders"
            });

            categoryRepository.AddOrUpdate(new CategoryModel {
                DisplayOrder    = 5,
                Title           = "کاربر",
                Slug            = StringHelpers.Slugify("User"),
                MetaKeywords    = "کاربر, User",
                MetaDescription = "توضیحات متا",
                CssClass        = "User"
            });

            categoryRepository.AddOrUpdate(new CategoryModel {
                DisplayOrder    = 6,
                Title           = "اس‌اس‌او",
                Slug            = StringHelpers.Slugify("SingleSignOn"),
                MetaKeywords    = "لاگین، فقط یک بار، ورود، SSO، Single Sign On",
                MetaDescription = "توضیحات متا",
                CssClass        = "SingleSignOn"
            });

            categoryRepository.AddOrUpdate(new CategoryModel {
                DisplayOrder    = 7,
                Title           = "خرید",
                Slug            = StringHelpers.Slugify("Shopping"),
                MetaKeywords    = "خرید, Purchase, فروشگاه, Shopping",
                MetaDescription = "توضیحات متا",
                CssClass        = "Shopping"
            });

            categoryRepository.AddOrUpdate(new CategoryModel {
                DisplayOrder    = 8,
                Title           = "نظرسنجی",
                Slug            = StringHelpers.Slugify("Polling"),
                MetaKeywords    = "نظرسنجی, Poll, Vote, Survey",
                MetaDescription = "توضیحات متا",
                CssClass        = "Polling"
            });

            categoryRepository.AddOrUpdate(new CategoryModel {
                DisplayOrder    = 9,
                Title           = "پروفایل",
                Slug            = StringHelpers.Slugify("Profile"),
                MetaKeywords    = "پروفایل, Profile, Social",
                MetaDescription = "توضیحات متا",
                CssClass        = "Profile"
            });

            categoryRepository.AddOrUpdate(new CategoryModel {
                DisplayOrder    = 10,
                Title           = "آفیس",
                Slug            = StringHelpers.Slugify("Office"),
                MetaKeywords    = "آفیس, Office, آفیس 2010, Office 2010, آفیس 2013, Office 2013, آفیس 365, Office 365, ورد, Word, اکسل, Excel, آوتلوک, اوتلوک, Outlook",
                MetaDescription = "توضیحات متا",
                CssClass        = "Office"
            });

            categoryRepository.AddOrUpdate(new CategoryModel {
                DisplayOrder    = 11,
                Title           = "رابط کاربری",
                Slug            = StringHelpers.Slugify("UserInterface"),
                MetaKeywords    = "رابط کاربری, UI, UX, XSL, XSLT, CSS",
                MetaDescription = "توضیحات متا",
                CssClass        = "UserInterface"
            });

            categoryRepository.AddOrUpdate(new CategoryModel {
                DisplayOrder    = 12,
                Title           = "اطلاع رسانی",
                Slug            = StringHelpers.Slugify("Notification"),
                MetaKeywords    = "اطلاع رسانی, Notification, Alert",
                MetaDescription = "توضیحات متا",
                CssClass        = "Notification"
            });

            categoryRepository.AddOrUpdate(new CategoryModel {
                DisplayOrder    = 13,
                Title           = "خبر",
                Slug            = StringHelpers.Slugify("NewsManagement"),
                MetaKeywords    = "خبر, News, News Management",
                MetaDescription = "توضیحات متا",
                CssClass        = "NewsManagement"
            });

            categoryRepository.AddOrUpdate(new CategoryModel {
                DisplayOrder    = 14,
                Title           = "زیرساخت",
                Slug            = StringHelpers.Slugify("Infrastructure"),
                MetaKeywords    = "زیرساخت, Infrastructure",
                MetaDescription = "توضیحات متا",
                CssClass        = "Infrastructure"
            });

            categoryRepository.AddOrUpdate(new CategoryModel {
                DisplayOrder    = 15,
                Title           = "اطلاعات روز",
                Slug            = StringHelpers.Slugify("DailyEvents"),
                MetaKeywords    = "اطلاعات روز",
                MetaDescription = "توضیحات متا",
                CssClass        = "DailyEvents"
            });

            categoryRepository.AddOrUpdate(new CategoryModel {
                DisplayOrder    = 16,
                Title           = "سی‌ام‌اس",
                Slug            = StringHelpers.Slugify("ContentManagement"),
                MetaKeywords    = "مدیریت محتوا, سیستم مدیریت محتوا, CMS, Content, Content Management",
                MetaDescription = "توضیحات متا",
                CssClass        = "ContentManagement"
            });

            categoryRepository.SaveChanges();
        }