public int UpdateStoreCustomerType(StoreCustomerTypeObject storeCustomerType)
 {
     try
     {
         if (storeCustomerType == null)
         {
             return(-2);
         }
         var duplicates = _repository.Count(m => m.Name.Trim().ToLower() == storeCustomerType.Name.Trim().ToLower() && (m.StoreCustomerTypeId != storeCustomerType.StoreCustomerTypeId));
         if (duplicates > 0)
         {
             return(-3);
         }
         var storeCustomerTypeEntity = ModelCrossMapper.Map <StoreCustomerTypeObject, StoreCustomerType>(storeCustomerType);
         if (storeCustomerTypeEntity == null || storeCustomerTypeEntity.StoreCustomerTypeId < 1)
         {
             return(-2);
         }
         _repository.Update(storeCustomerTypeEntity);
         _uoWork.SaveChanges();
         return(5);
     }
     catch (Exception ex)
     {
         ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
         return(-2);
     }
 }
 public long AddStoreCustomerType(StoreCustomerTypeObject storeCustomerType)
 {
     try
     {
         if (storeCustomerType == null)
         {
             return(-2);
         }
         var duplicates = _repository.Count(m => m.Name.Trim().ToLower() == storeCustomerType.Name.Trim().ToLower() && (m.StoreCustomerTypeId != storeCustomerType.StoreCustomerTypeId));
         if (duplicates > 0)
         {
             return(-3);
         }
         var storeCustomerTypeEntity = ModelCrossMapper.Map <StoreCustomerTypeObject, StoreCustomerType>(storeCustomerType);
         if (storeCustomerTypeEntity == null || string.IsNullOrEmpty(storeCustomerTypeEntity.Name))
         {
             return(-2);
         }
         var returnStatus = _repository.Add(storeCustomerTypeEntity);
         _uoWork.SaveChanges();
         return(returnStatus.StoreCustomerTypeId);
     }
     catch (Exception ex)
     {
         ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
        private GenericValidator ValidateStoreCustomerType(StoreCustomerTypeObject customerType)
        {
            var gVal = new GenericValidator();

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

            gVal.Code = 5;
            return(gVal);
        }
Exemple #4
0
 public int UpdateStoreCustomerType(StoreCustomerTypeObject storeCustomerTypeAccount)
 {
     try
     {
         return(_storeCustomerTypeAccountRepository.UpdateStoreCustomerType(storeCustomerTypeAccount));
     }
     catch (Exception ex)
     {
         ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
         return(-2);
     }
 }
        public ActionResult AddStoreCustomerType(StoreCustomerTypeObject customerType)
        {
            var gVal = new GenericValidator();

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

                    var k = new StoreCustomerTypeServices().AddStoreCustomerType(customerType);
                    if (k < 1)
                    {
                        gVal.Code  = -1;
                        gVal.Error = k == -3 ? message_Feedback.Item_Duplicate : message_Feedback.Insertion_Failure;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }
                    gVal.Code = 5;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }
                gVal.Code  = -1;
                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));
            }
        }
        public ActionResult EditStoreCustomerType(StoreCustomerTypeObject customerType)
        {
            var gVal = new GenericValidator();

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

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

                    var oldStoreCustomerType = Session["_customerType"] as StoreCustomerTypeObject;
                    if (oldStoreCustomerType == null || oldStoreCustomerType.StoreCustomerTypeId < 1)
                    {
                        gVal.Code  = -1;
                        gVal.Error = message_Feedback.Session_Time_Out;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }

                    oldStoreCustomerType.Name = customerType.Name.Trim();
                    oldStoreCustomerType.Code = customerType.Code.Trim();

                    if (!string.IsNullOrEmpty(customerType.Description))
                    {
                        oldStoreCustomerType.Description = customerType.Description.Trim();
                    }
                    var k = new StoreCustomerTypeServices().UpdateStoreCustomerType(oldStoreCustomerType);
                    if (k < 1)
                    {
                        gVal.Code  = -1;
                        gVal.Error = k == -3 ? message_Feedback.Item_Duplicate : message_Feedback.Update_Failure;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }
                    gVal.Code  = 5;
                    gVal.Error = message_Feedback.Model_State_Error;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = -1;
                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));
            }
        }