public GeneralResponse AddPersenceSupport(AddPersenceSupportRequest request)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                PersenceSupport persenceSupport = new PersenceSupport();
                persenceSupport.ID                  = Guid.NewGuid();
                persenceSupport.CreateDate          = PersianDateTime.Now;
                persenceSupport.CreateEmployee      = _employeeRepository.FindBy(request.CreateEmployeeID);
                persenceSupport.ConnectedToInternet = request.ConnectedToInternet;
                persenceSupport.Customer            = this._customerRepository.FindBy(request.CustomerID);
                persenceSupport.PlanDate            = request.PlanDate;
                persenceSupport.PlanNote            = request.PlanNote;
                persenceSupport.PlanTimeFrom        = request.PlanTimeFrom;
                persenceSupport.PlanTimeTo          = request.PlanTimeTo;
                persenceSupport.Problem             = request.Problem;
                persenceSupport.SupportType         = request.SupportType;
                persenceSupport.RowVersion          = 1;
                persenceSupport.Installer           = _employeeRepository.FindBy(request.InstallerID);

                #region Validation

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

                    return(response);
                }

                #endregion

                _persenceSupportRepository.Add(persenceSupport);
                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
            }

            return(response);
        }
        public GeneralResponse EditPersenceSupport(EditPersenceSupportRequest request)
        {
            GeneralResponse response        = new GeneralResponse();
            PersenceSupport persenceSupport = new PersenceSupport();

            persenceSupport = _persenceSupportRepository.FindBy(request.ID);

            if (persenceSupport != null)
            {
                try
                {
                    // اگر تحویل شده بود قابل ویرایش نباشد
                    if (persenceSupport.Delivered)
                    {
                        response.ErrorMessages.Add("DeliveredAndCanNotBeEdited");
                        return(response);
                    }

                    persenceSupport.ModifiedDate     = PersianDateTime.Now;
                    persenceSupport.ModifiedEmployee = _employeeRepository.FindBy(request.ModifiedEmployeeID);
                    persenceSupport.PlanDate         = request.PlanDate;
                    persenceSupport.PlanNote         = request.PlanNote;
                    persenceSupport.PlanTimeFrom     = request.PlanTimeFrom;
                    persenceSupport.PlanTimeTo       = request.PlanTimeTo;
                    persenceSupport.Problem          = request.Problem;
                    persenceSupport.SupportType      = request.SupportType;
                    persenceSupport.Installer        = _employeeRepository.FindBy(request.InstallerID);

                    #region RowVersion Check

                    if (persenceSupport.RowVersion != request.RowVersion)
                    {
                        response.ErrorMessages.Add("کارشناس محترم، یک کاربر همزمان با شما در حال ویرایش این رکورد است. بنابراین اطلاعات شما ذخیره نمی شود.");
                        return(response);
                    }
                    else
                    {
                        persenceSupport.RowVersion += 1;
                        response.rowVersion         = persenceSupport.RowVersion;
                    }

                    #endregion

                    #region Validation

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

                        return(response);
                    }

                    #endregion

                    _persenceSupportRepository.Save(persenceSupport);
                    _uow.Commit();
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                }
            }
            else
            {
                response.ErrorMessages.Add("NoItemToEditKey");
            }
            return(response);
        }
        public GeneralResponse DeliverPersenceSupport(Guid PersenceSupportID, Guid InstallerID, bool Delivered, string DeliverDate, string DeliverNote, string DeliverTime, long ReceivedCost, int RowVersion)
        {
            GeneralResponse response        = new GeneralResponse();
            PersenceSupport persenceSupport = new PersenceSupport();

            persenceSupport = _persenceSupportRepository.FindBy(PersenceSupportID);

            if (persenceSupport != null)
            {
                try
                {
                    // اگر قبلاً تحویل شده بود انجام نشود
                    if (persenceSupport.Delivered)
                    {
                        response.ErrorMessages.Add("DeliveredAndCanNotBeDeliveredAgain");
                        return(response);
                    }

                    persenceSupport.DeliverDate  = DeliverDate;
                    persenceSupport.Delivered    = Delivered;
                    persenceSupport.DeliverNote  = DeliverNote;
                    persenceSupport.DeliverTime  = DeliverTime;
                    persenceSupport.Installer    = this._employeeRepository.FindBy(InstallerID);
                    persenceSupport.ReceivedCost = ReceivedCost;

                    #region RowVersion Check

                    if (persenceSupport.RowVersion != RowVersion)
                    {
                        response.ErrorMessages.Add("کارشناس محترم، یک کاربر همزمان با شما در حال ویرایش این رکورد است. بنابراین اطلاعات شما ذخیره نمی شود.");
                        return(response);
                    }
                    else
                    {
                        persenceSupport.RowVersion += 1;
                        response.rowVersion         = persenceSupport.RowVersion;
                    }

                    #endregion

                    #region Validation

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

                        return(response);
                    }

                    #endregion

                    _persenceSupportRepository.Save(persenceSupport);
                    _uow.Commit();
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                }
            }

            return(response);
        }