示例#1
0
 //
 // GET: /pradmin/categories/500001
 public ActionResult Categories(int id)
 {
     var model = new PosCategoriesListViewModel();
     var db = new ProductRepository();
     throw new NotImplementedException("Need to Ninject CategoryRepository!");
     //model.Organization = new OrganizationRepository().Items.Single(x => x.Id == id);
     //model.Categories = db.Categories.Where(x => x.OrganizationId == model.Organization.Id).ToList();
     return View(model);
 }
示例#2
0
 public ActionResult AllCategories()
 {
     var db = new ProductRepository();
     return View(db.Categories);
 }
示例#3
0
        //
        // GET: /pradmin/get?posid=100001
        public ActionResult Get()
        {
            // ID of POS must be!
            int posId = int.Parse(Request["posid"]);
            InfoFormat("Loading products for POS ID #{0}...", posId);

            ProductRepository db = new ProductRepository();

            StringBuilder sbMain = new StringBuilder();
            StringBuilder sb = new StringBuilder();
            var products = db.Items
                .Where(x => x.PosId == posId && x.StatusId == (byte)Status.Approved)
                .Take(200)
                .ToList();
            InfoFormat("Got {0} products for POS ID #{1}", products == null ? "NULL" : products.Count.ToString(), posId);
            //var shops = dbPos.Items.ToList();
            string callback = Request["callback"];

            // Returns JSON array of all products for specified POS

            foreach(var p in products)
            {

                sb.Clear();
                //foreach(var kvp in p.GetQuantityForAllSizes())
                //{
                //    sb.AppendFormat(", '{0}': {1}", kvp.Key, kvp.Value);
                //}

                sbMain.AppendFormat("{{ name: \"{0}\", code: \"{1}\", price_minor: '{2}', amount: {3} {4} }},", p.Name, p.InternalCode, p.PosId, 0, sb.ToString());
            }

            return Content(string.Format("{0}({{'data': [ {1} ]}})", callback, sbMain.ToString()));
        }
示例#4
0
        public ActionResult EditCategory(int id, FormCollection f)
        {
            OnBalance.Domain.Entities.Category model = null;
            try
            {
                var db = new ProductRepository();
                model = _productRepository.GetCategory(id);
                if(model == null)
                {
                    ErrorFormat("User #{0} tries to update non-existing category #{1}!", User.Identity.Name, id);
                    return RedirectToAction("notfound", "help");
                }

                UpdateModel(model);
                db.SubmitChanges();
                return RedirectToAction("editcategory", new { id = id });
            } catch(Exception ex)
            {
                Error(string.Concat("Error updating category #", id), ex);
                ModelState.AddModelError("", ex.Message);
            }

            return View(model);
        }
示例#5
0
        public ActionResult EditCategory(int id)
        {
            CategoryStructureViewModel vm = new CategoryStructureViewModel();
            //var model = new Category();
            var db = new ProductRepository();
            throw new NotImplementedException("vm.Category = db.GetCategory(id)");
            //vm.Category = db.GetCategory(id);
            if( vm.Category == null )
            {
                ErrorFormat("User #{0} tries to edit non-existing category #{1}!", User.Identity.Name, id);
                return RedirectToAction("notfound", "help");
            }

            //model.Organization = new OrganizationRepository().Items.Single(x => x.Id == model.Category.id);
            return View(vm);
        }
示例#6
0
        //
        // POST: /pradmin/dosavestructure
        //[HttpPost]
        public ActionResult DoSaveStructure(int id, CategoryStructureViewModel vm /*FormCollection f, List<CategoryStructure> CategoryStructure*/)
        {
            try
            {
                var db = new OnBalance.Domain.Entities.CategoryStructureRepository();
                var dbProduct = new ProductRepository();
                //Category model = dbProduct.GetCategory(id);
                string newName = Request["NewName"];
                bool isNewApproved = false;

                //InfoFormat("User #{0} updates Category #{1} to name: {2}, status: {3} ({4}), organization: #{5}", User.Identity.Name, vm.Category.Id, vm.Category.Name, vm.Category.StatusName, vm.Category.StatusId, vm.Category.OrganizationId);
                //InfoFormat("User #{0} updates Category #{1} to name: {2}, status: {3} ({4}), organization: #{5}", User.Identity.Name, model.Id, model.Name, model.StatusName, model.StatusId, model.OrganizationId);
                throw new NotImplementedException("dbProduct.Save(vm.Category)");
                //dbProduct.Save(vm.Category);
                //UpdateModel<Category>(model, "Category__");
                //dbProduct.SubmitChanges();

                //if(CategoryStructure != null)
                //{
                    Info("Updating category structure...");
                    foreach(var item in vm.CategoryStructure)
                    {
                        InfoFormat("  Category structure: #{0, -8}. {1}", item.Id, item.FieldName);
                        throw new NotImplementedException("db.Update(item)");
                        //db.Update(item);
                    }
                //}

                if(string.IsNullOrEmpty(newName) == false)
                {
                    bool.TryParse(Request["NewStatus"], out isNewApproved);
                    OnBalance.Domain.Entities.CategoryStructure cs = new OnBalance.Domain.Entities.CategoryStructure();
                    cs.FieldName = newName;
                    cs.StatusId = isNewApproved ? (byte)Status.Approved : (byte)Status.Deleted;
                    cs.CategoryId = vm.Category.Id;
                    db.Add(cs);
                }

                db.SubmitChanges();

                return PartialView("CategoryStructure", vm.Category);
            } catch(Exception ex)
            {
                Error("Error updating Category structure!", ex);
                throw ex;
            }
        }