コード例 #1
0
        public ActionResult AjaxView()
        {
            var categoryModel = _categoryDa.GetById(ArrId.FirstOrDefault());

            ViewData.Model = categoryModel;
            return(View());
        }
コード例 #2
0
        public ActionResult GetById(string key, int id)
        {
            var obj = key != Keyapi ? new Base.Category() : _da.GetById(id);;

            return(Json(obj, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public ActionResult Add(string key, string codelogin, string json, Guid userId)
        {
            var msg   = new JsonMessage(false, "Thêm mới dữ liệu thành công.");
            var model = new Category_Recipe();

            try
            {
                if (key != Keyapi)
                {
                    return(Json(0, JsonRequestBehavior.AllowGet));
                }
                UpdateModel(model);
                model.IsDeleted  = false;
                model.UserId     = userId;
                model.DateCreate = DateTime.Now.TotalSeconds();
                var lst        = GetListCategoryRecipeItem(codelogin);
                var caterecipe = model.Category_Product_Recipe.Where(c => c.IsDeleted == false);
                var result2    = lst.Where(p => caterecipe.All(p2 => p2.ProductId != p.ProductId)).ToList();
                foreach (var item in result2)
                {
                    model.Category_Product_Recipe.Add(item);
                }

                var lstmap  = GetListMappingCategoryRecipeItem(codelogin);
                var catemap = model.Mapping_Category_Recipe.Where(c => c.IsDeleted == false);
                var result  = lstmap.Where(a => catemap.All(c => c.CategoryID != a.CategoryID)).ToList();
                foreach (var item in result)
                {
                    model.Mapping_Category_Recipe.Add(item);
                }

                _da.Add(model);
                _da.Save();
                if (model.IsUse == true)
                {
                    decimal?cost       = 0;
                    decimal?priceFinal = 0;
                    foreach (var items in model.Category_Product_Recipe.Where(c => c.IsCheck == true && (!c.IsDeleted.HasValue || c.IsDeleted == false)))
                    {
                        var temp = _detailDa.GetById(items.ProductId ?? 0);
                        cost          += items.Price * items.Quantity;
                        priceFinal    += items.Price == 0 ? 0 : (items.Price + temp.Category.Percent * 1000) * items.Quantity + items.Incurred;
                        temp.PriceCost = items.Price;
                        temp.Value     = items.Price;
                        temp.Percent   = temp.Category.Percent;
                        temp.PriceOld  = items.Price + (temp.Incurred ?? 0) + (temp.Percent ?? 0) * 1000;
                        temp.Incurred  = items.Incurred;
                        temp.Price     = items.PriceProduct;
                        _detailDa.Save();
                    }

                    foreach (var items in model.Mapping_Category_Recipe.Where(c => c.IsCheck == true && (!c.IsDeleted.HasValue || c.IsDeleted == false)))
                    {
                        //var temp = _detailDa.GetById(model.CategoryID ?? 0);

                        //priceFinal += items.PriceProduct * items.Quantity;
                        //temp.Price = items.PriceProduct;
                        //temp.PriceCost = items.Price;
                        //temp.Incurred = items.Incurred;
                        //temp.Price = items.PriceProduct;
                        //temp.Value = items.Price;
                        //temp.PriceOld = items.Price + (temp.Incurred ?? 0) + (temp.Percent ?? 0) * 1000;
                        //_detailDa.Save();
                        var temp1 = _categoryDa.GetById(model.CategoryID ?? 0);
                        cost                  += items.Price;
                        priceFinal            += items.Price + (temp1.Percent * 1000 * items.Quantity) + items.Incurred;
                        temp1.PriceRecipeFinal = items.Price + (items.Quantity * temp1.Percent * 1000) + items.Incurred;
                        _detailDa.Save();
                    }
                    var cate = _categoryDa.GetById(model.CategoryID ?? 0);
                    cate.PriceRecipe        = cost;
                    cate.PriceRecipeFinal   = priceFinal;
                    cate.TotalIncurredFinal = model.TotalIncurred;
                    _categoryDa.Save();
                }
            }
            catch (Exception ex)
            {
                Log2File.LogExceptionToFile(ex);
                msg.Erros   = true;
                msg.Message = "Dữ liệu chưa được thêm mới";
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }