Ejemplo n.º 1
0
        /// <summary>
        /// Displays new product form (fro Ajax)
        /// </summary>
        /// <param name="id">POS ID</param>
        public ActionResult GetNewProduct(int id)
        {
            try
            {
                var model = new ProductNew();
                var pos = _organizationRepository.GetById(id);
                model.PosId = pos.Id;
                model.PosName = pos.Name;
                model.CategoryId = int.Parse(Request["categoryId"]);
                model.TotalSizes = HasRequestParameter("sizes") ? int.Parse(Request["sizes"]) : 0;
                var category = _productRepository.Categories.First(x => x.Id == model.CategoryId);
                    //.Select(x => new Category { Id = x.Id, Name = x.Name })
                    //.First(x => x.Equals(model.CategoryId));
                model.CategoryName = category.Name;

                return PartialView(model);
            }
            catch (Exception ex)
            {
                Error("Error getting new product form", ex);
                throw;
            }
        }
Ejemplo n.º 2
0
        public ActionResult DoNewProduct(ProductNew model)
        {
            try
            {
                decimal d;
                var productPdo = new Domain.Entities.Product();
                productPdo.PosId = model.PosId;
                productPdo.CategoryId = model.CategoryId;
                productPdo.Name = HttpUtility.HtmlEncode(model.ProductName);
                productPdo.CreatedAt = DateTime.UtcNow;
                productPdo.UserId = "gj";
                productPdo.StatusId = (byte)Status.Pending;
                productPdo.InternalCode = model.InternalCode.StartsWith(productPdo.UserId, StringComparison.InvariantCultureIgnoreCase) ? model.InternalCode : String.Concat(productPdo.UserId.ToUpper(), "_ES_", model.InternalCode);
                productPdo.Uid = string.Concat("GJ_ES_", model.InternalCode);
                if (decimal.TryParse(model.PriceStr, out d))
                {
                    productPdo.Price = d;
                }

                _productRepository.Save(productPdo);
                _productRepository.SubmitChanges();

                var product = new Product(productPdo);

                ViewBag.TotalSizes = model.TotalSizes;
                return PartialView(product);
            }
            catch (Exception ex)
            {

                throw;
            }
        }