public long AddStoreItem(StoreItemObject storeItem)
 {
     try
     {
         if (storeItem == null)
         {
             return(-2);
         }
         if (_repository.Count(m => m.Name.Trim().ToLower() == storeItem.Name.Trim().ToLower() && m.StoreItemBrandId == storeItem.StoreItemBrandId && m.StoreItemCategoryId == storeItem.StoreItemCategoryId && m.StoreItemTypeId == storeItem.StoreItemTypeId) > 0)
         {
             return(-3);
         }
         var storeItemEntity = ModelCrossMapper.Map <StoreItemObject, StoreItem>(storeItem);
         if (storeItemEntity == null || string.IsNullOrEmpty(storeItemEntity.Name))
         {
             return(-2);
         }
         var returnStatus = _repository.Add(storeItemEntity);
         _uoWork.SaveChanges();
         return(returnStatus.StoreItemId);
     }
     catch (Exception ex)
     {
         ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
        public Int32 UpdateStoreItem(StoreItemObject storeItem)
        {
            try
            {
                if (storeItem == null)
                {
                    return(-2);
                }

                if (_repository.Count(m => m.Name.Trim().ToLower() == storeItem.Name.Trim().ToLower() && m.StoreItemBrandId == storeItem.StoreItemBrandId && m.StoreItemCategoryId == storeItem.StoreItemCategoryId && m.StoreItemTypeId == storeItem.StoreItemTypeId && (m.StoreItemId != storeItem.StoreItemId)) > 0)
                {
                    return(-3);
                }

                var storeItemEntity = ModelCrossMapper.Map <StoreItemObject, StoreItem>(storeItem);
                if (storeItemEntity == null || storeItemEntity.StoreItemId < 1)
                {
                    return(-2);
                }
                _repository.Update(storeItemEntity);
                _uoWork.SaveChanges();
                return(5);
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                return(-2);
            }
        }
示例#3
0
        public ActionResult AddStoreItem(StoreItemObject product)
        {
            var gVal = new GenericValidator();

            try
            {
                if (ModelState.IsValid)
                {
                    var valStatus = ValidateStoreItem(product);
                    if (valStatus.Code < 1)
                    {
                        gVal.Code  = -1;
                        gVal.Error = valStatus.Error;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }

                    //var logoPath = SaveFile("");
                    //if (!string.IsNullOrEmpty(logoPath))
                    //{
                    //    product.SampleImagePath = logoPath;
                    //}
                    var k = new StoreItemServices().AddStoreItem(product);
                    if (k < 1)
                    {
                        if (k == -3)
                        {
                            product.Name = message_Feedback.Item_Duplicate;
                        }
                        if (k == -4)
                        {
                            product.Name = message_Feedback.Insertion_Failure;
                        }
                        if (k != -3 && k != -4)
                        {
                            product.Name = message_Feedback.Insertion_Failure;
                        }
                        gVal.Code = -1;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }

                    gVal.Code  = k;
                    gVal.Error = message_Feedback.Insertion_Success;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = -5;
                gVal.Error = message_Feedback.Model_State_Error;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Process_Failed;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
示例#4
0
 public int UpdateStoreItem(StoreItemObject storeItem)
 {
     try
     {
         return(_storeItemRepository.UpdateStoreItem(storeItem));
     }
     catch (Exception ex)
     {
         ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
         return(-2);
     }
 }
示例#5
0
 public long AddStoreItem(StoreItemObject storeItem)
 {
     try
     {
         return(_storeItemRepository.AddStoreItem(storeItem));
     }
     catch (Exception ex)
     {
         ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
示例#6
0
        private GenericValidator ValidateStoreItem(StoreItemObject product)
        {
            var gVal = new GenericValidator();

            if (product == null)
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Fatal_Error;
                return(gVal);
            }
            if (string.IsNullOrEmpty(product.Name))
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Product_Name_Error;
                return(gVal);
            }

            if (product.ChartOfAccountId < 1)
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Chart_Of_Account_Selection_Error;
                return(gVal);
            }
            if (product.StoreItemBrandId < 1)
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Product_Brand_Selection_Error;
                return(gVal);
            }
            if (product.StoreItemCategoryId < 1)
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Product_Category_Selection_Error;
                return(gVal);
            }
            if (product.StoreItemTypeId < 1)
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Product_Type_Selection_Error;
                return(gVal);
            }
            gVal.Code = 5;
            return(gVal);
        }
示例#7
0
        public ActionResult EditStoreItem(StoreItemObject product)
        {
            var gVal = new GenericValidator();

            try
            {
                if (ModelState.IsValid)
                {
                    var valStatus = ValidateStoreItem(product);
                    if (valStatus.Code < 1)
                    {
                        gVal.Code  = -1;
                        gVal.Error = valStatus.Error;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }

                    if (Session["_product"] == null)
                    {
                        gVal.Code  = -5;
                        gVal.Error = message_Feedback.Session_Time_Out;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }

                    var oldStoreItem = Session["_product"] as StoreItemObject;
                    if (oldStoreItem == null || oldStoreItem.StoreItemId < 1)
                    {
                        gVal.Code  = -5;
                        gVal.Error = message_Feedback.Session_Time_Out;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }

                    oldStoreItem.Name                = product.Name.Trim();
                    oldStoreItem.ChartOfAccountId    = product.ChartOfAccountId;
                    oldStoreItem.StoreItemBrandId    = product.StoreItemBrandId;
                    oldStoreItem.StoreItemTypeId     = product.StoreItemTypeId;
                    oldStoreItem.StoreItemCategoryId = product.StoreItemCategoryId;

                    if (product.ParentItemId > 0)
                    {
                        oldStoreItem.ParentItemId = product.ParentItemId;
                    }

                    if (!string.IsNullOrEmpty(product.Description))
                    {
                        oldStoreItem.Description = product.Description.Trim();
                    }

                    //var formerSampleImagePath = string.Empty;
                    //if (!string.IsNullOrEmpty(oldStoreItem.SampleImagePath))
                    //{
                    //    formerSampleImagePath = oldStoreItem.SampleImagePath;
                    //}

                    //var logoPath = SaveFile(formerSampleImagePath);

                    //if (!string.IsNullOrEmpty(logoPath))
                    //{
                    //    oldStoreItem.SampleImagePath = logoPath;
                    //}

                    var k = new StoreItemServices().UpdateStoreItem(oldStoreItem);
                    if (k < 1)
                    {
                        gVal.Error = k == -3 ? message_Feedback.Item_Duplicate : message_Feedback.Update_Failure;

                        gVal.Code = -1;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }
                    gVal.Code  = 5;
                    gVal.Error = message_Feedback.Update_Success;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = -5;
                gVal.Error = message_Feedback.Model_State_Error;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Process_Failed;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }