Beispiel #1
0
        public GeneralResponse AddCreditService(AddCreditServiceRequestOld request)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                CreditService creditService = new CreditService();
                creditService.ID                = Guid.NewGuid();
                creditService.CreateDate        = PersianDateTime.Now;
                creditService.CreateEmployee    = _employeeRepository.FindBy(request.CreateEmployeeID);
                creditService.CreditServiceCode = request.CreditServiceCode;
                creditService.Discontinued      = request.Discontinued;
                creditService.ExpDays           = request.ExpDays;
                creditService.Imposition        = request.Imposition;
                creditService.MaxDiscount       = request.MaxDiscount;
                creditService.Network           = this._networkRepository.FindBy(request.NetworkID);
                creditService.PurchaseUnitPrice = request.PurchaseUnitPrice;
                creditService.ResellerUnitPrice = request.ResellerUnitPrice;
                creditService.ServiceName       = request.ServiceName;
                creditService.UnitPrice         = request.UnitPrice;
                creditService.Note              = request.Note;
                creditService.Discontinued      = request.Discontinued;
                creditService.SortOrder         = GetSortOrder();
                creditService.RowVersion        = 1;

                // Validation
                if (creditService.GetBrokenRules().Count() > 0)
                {
                    foreach (BusinessRule businessRule in creditService.GetBrokenRules())
                    {
                        response.ErrorMessages.Add(businessRule.Rule);
                    }

                    return(response);
                }

                _creditServiceRepository.Add(creditService);
                _uow.Commit();
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException.Message.Substring(0, 177) == @"The INSERT statement conflicted with the CHECK constraint ""CK_CreditService"". The conflict occurred in database ""Saman"", table ""Store.CreditService"", column 'CreditServiceCode'.")
                {
                    response.ErrorMessages.Add("MustBeBegin3000Key");
                }
                else
                {
                    response.ErrorMessages.Add(ex.Message);
                    if (ex.InnerException != null)
                    {
                        response.ErrorMessages.Add(ex.InnerException.Message);
                    }
                }
            }

            return(response);
        }
Beispiel #2
0
        public GeneralResponse EditCreditServices(EditCreditServiceRequest request, Guid EmployeeID)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                CreditService creditService = _creditServiceRepository.FindBy(request.ID);

                if (creditService != null)
                {
                    #region Validate Uncredit Service Code

                    string _errorMessag = EditValidate(request.CreditServiceCode, request.ServiceName, request.ID);

                    if (_errorMessag != "NoError")
                    {
                        response.ErrorMessages.Add(_errorMessag);
                        return(response);
                    }

                    #endregion


                    if (request.MaxDiscount > request.UnitPrice)
                    {
                        response.ErrorMessages.Add("تخفیف نمیتواند بیش از قیمت پایه باشد");
                        return(response);
                    }

                    creditService.ModifiedDate      = PersianDateTime.Now;
                    creditService.ModifiedEmployee  = _employeeRepository.FindBy(EmployeeID);
                    creditService.CreditServiceCode = request.CreditServiceCode;
                    creditService.Discontinued      = request.Discontinued;
                    creditService.ExpDays           = request.ExpDays;
                    creditService.Imposition        = request.Imposition;
                    creditService.MaxDiscount       = request.MaxDiscount;
                    if (creditService.Network.ID != request.NetworkID)
                    {
                        creditService.Network = this._networkRepository.FindBy(request.NetworkID);
                    }
                    creditService.PurchaseUnitPrice = request.PurchaseUnitPrice;
                    creditService.ResellerUnitPrice = request.ResellerUnitPrice;
                    creditService.Bonus             = request.Bonus;
                    creditService.Comission         = request.Comission;
                    if (request.ServiceName != null)
                    {
                        creditService.ServiceName = request.ServiceName;
                    }
                    creditService.UnitPrice = request.UnitPrice;
                    if (request.Note != null)
                    {
                        creditService.Note = request.Note;
                    }
                    creditService.Discontinued = request.Discontinued;

                    #region Validation

                    if (creditService.RowVersion != request.RowVersion)
                    {
                        response.ErrorMessages.Add("EditConcurrencyKey");
                        return(response);
                    }
                    else
                    {
                        creditService.RowVersion += 1;
                    }

                    if (creditService.GetBrokenRules().Count() > 0)
                    {
                        foreach (BusinessRule businessRule in creditService.GetBrokenRules())
                        {
                            response.ErrorMessages.Add(businessRule.Rule);
                        }

                        return(response);
                    }

                    #endregion

                    _creditServiceRepository.Save(creditService);
                }
                else
                {
                    response.ErrorMessages.Add("NoItemToEditKey");
                }
                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }

            return(response);
        }
Beispiel #3
0
        public GeneralResponse EditCreditService(EditCreditServiceRequestOld request)
        {
            GeneralResponse response      = new GeneralResponse();
            CreditService   creditService = new CreditService();

            creditService = _creditServiceRepository.FindBy(request.ID);

            if (creditService != null)
            {
                try
                {
                    creditService.ModifiedDate      = PersianDateTime.Now;
                    creditService.ModifiedEmployee  = _employeeRepository.FindBy(request.ModifiedEmployeeID);
                    creditService.CreditServiceCode = request.CreditServiceCode;
                    creditService.Discontinued      = request.Discontinued;
                    creditService.ExpDays           = request.ExpDays;
                    creditService.Imposition        = request.Imposition;
                    creditService.MaxDiscount       = request.MaxDiscount;
                    creditService.Network           = this._networkRepository.FindBy(request.NetworkID);
                    creditService.PurchaseUnitPrice = request.PurchaseUnitPrice;
                    creditService.ResellerUnitPrice = request.ResellerUnitPrice;
                    if (request.ServiceName != null)
                    {
                        creditService.ServiceName = request.ServiceName;
                    }
                    creditService.UnitPrice = request.UnitPrice;
                    if (request.Note != null)
                    {
                        creditService.Note = request.Note;
                    }
                    creditService.Discontinued = request.Discontinued;

                    if (creditService.RowVersion != request.RowVersion)
                    {
                        response.ErrorMessages.Add("EditConcurrencyKey");
                        return(response);
                    }
                    else
                    {
                        creditService.RowVersion += 1;
                    }

                    if (creditService.GetBrokenRules().Count() > 0)
                    {
                        foreach (BusinessRule businessRule in creditService.GetBrokenRules())
                        {
                            response.ErrorMessages.Add(businessRule.Rule);
                        }

                        return(response);
                    }

                    _creditServiceRepository.Save(creditService);
                    _uow.Commit();

                    ////response.success = true;
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                }
            }
            else
            {
                response.ErrorMessages.Add("NoItemToEditKey");
            }
            return(response);
        }