public bool IsQuantityRequired(int ProductID)
 {
     using (dbUltraCoralEntities db = new dbUltraCoralEntities())
     {
         tblProduct p = db.tblProducts.Find(ProductID);
         if (p != null)
         {
             tblProductSize ps = db.tblProductSizes.Find(p.SizeID);
             if (ps != null)
             {
                 return(ps.QuanReq ?? false);
             }
         }
     }
     return(false);
 }
Exemple #2
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);
        }