public JsonResult AddSize(ProductSizeViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var result = new { Result = "Erro", Error = true, Id = 0 };
                    return(Json(result));
                }

                if (!_unitOfWork.Repository <ProductSize>().Any(x => x.Size.ToUpper() == model.Size.ToUpper()))
                {
                    ProductSize Size = new ProductSize
                    {
                        AddedDate    = DateTime.Now,
                        ModifiedDate = DateTime.Now,

                        Size = model.Size,
                    };

                    _unitOfWork.Repository <ProductSize>().Insert(Size);
                    var result = new { Result = "Tamanho Inserido com sucesso", Error = false, Id = Size.Id };
                    return(Json(result));
                }
                else
                {
                    var result = new { Result = "Erro: O Tamanho inserido já existe", Error = true };
                    return(Json(result));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public IActionResult Create()
        {
            ProductSizeViewModel productSizeViewModel = new ProductSizeViewModel
            {
                Products = db.Products.ToList(),
                Sizes    = db.Sizes.ToList()
            };

            return(View(productSizeViewModel));
        }
        public IActionResult Create(ProductSize productSize, ProductSizeViewModel productSizeViewModel, Product product, Size size)
        {
            size.Number         = productSizeViewModel.NumberSize;
            product.ProductName = productSizeViewModel.SneakerName;

            productSize.ProductId = productSizeViewModel.SelectProduct;
            productSize.SizeId    = productSizeViewModel.SelectSize;

            db.ProductSizes.Add(productSize);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public IActionResult AddSize()
        {
            try
            {
                ProductSizeViewModel Size = new ProductSizeViewModel();

                return(PartialView("~/Views/ProductSize/_AddSize.cshtml", Size));
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 5
0
 private void FillProductSizeViewModelWithMetrics(ProductSizeViewModel viewModel)
 {
     viewModel.SizeMetricDimensions = new SelectList(new[]
     {
         new SelectListItem
         {
             Text  = T("cm").ToString(),
             Value = Enum.GetName(typeof(SizeMetricDimension), SizeMetricDimension.Centimetre)
         },
         new SelectListItem
         {
             Text  = T("in").ToString(),
             Value = Enum.GetName(typeof(SizeMetricDimension), SizeMetricDimension.Inch)
         }
     }, "Value", "Text");
 }
Esempio n. 6
0
 private void FillProductSizeViewModelWithSizeCodes(ProductSizeViewModel viewModel)
 {
     viewModel.SizeCodes = _sizeCodeRepository.Table
                           .ToList();
 }
Esempio n. 7
0
        public SavingResult SaveRecord(ProductSizeViewModel ViewModel)
        {
            SavingResult res = new SavingResult();

            if (String.IsNullOrWhiteSpace(ViewModel.ProductSizeName))
            {
                res.ExecutionResult = eExecutionResult.ValidationError;
                res.ValidationError = "Please enter size name";
                return(res);
            }

            using (dbUltraCoralEntities db = new dbUltraCoralEntities())
            {
                if (CheckDuplicate(ViewModel.ProductSizeID, ViewModel.ProductSizeName))
                {
                    res.ExecutionResult = eExecutionResult.ValidationError;
                    res.ValidationError = "Can not accept duplicate values. The size name is already exists.";
                    return(res);
                }

                tblProductSize SaveModel = null;
                if (ViewModel.ProductSizeID == 0)
                {
                    SaveModel = new tblProductSize()
                    {
                        rcdt  = DateTime.Now,
                        rcuid = Common.Props.LoginUser.UserID
                    };
                    db.tblProductSizes.Add(SaveModel);
                }
                else
                {
                    SaveModel = db.tblProductSizes.FirstOrDefault(r => r.ProductSizeID == ViewModel.ProductSizeID);
                    if (SaveModel == null)
                    {
                        res.ExecutionResult = eExecutionResult.ValidationError;
                        res.ValidationError = "Selected user has been deleted over network. Can not find user's details. Please retry.";
                        return(res);
                    }

                    SaveModel.redt  = DateTime.Now;
                    SaveModel.reuid = Common.Props.LoginUser.UserID;

                    db.tblProductSizes.Attach(SaveModel);
                    db.Entry(SaveModel).State = System.Data.Entity.EntityState.Modified;
                }

                SaveModel.ProductSizeName = ViewModel.ProductSizeName;
                SaveModel.QuanReq         = ViewModel.QuanReq;
                //--
                try
                {
                    db.SaveChanges();
                    res.PrimeKeyValue   = SaveModel.ProductSizeID;
                    res.ExecutionResult = eExecutionResult.CommitedSucessfuly;
                }
                catch (Exception ex)
                {
                    ex = Common.Functions.FindFinalError(ex);

                    res.ExecutionResult = eExecutionResult.ErrorWhileExecuting;
                    res.Exception       = ex;
                }
            }
            return(res);
        }