Пример #1
0
        private void btnAddMonth_Click(object sender, EventArgs e)
        {
            PersianDate pd = new PersianDate(calendar.AddMonths(DateTime.Now, 2));

            lblMessage.Text   = pd.ToString();
            lblToWritten.Text = pd.ToWritten();
        }
Пример #2
0
        static public DateTime GetStartOfNextMonth(DateTime st1)
        {
            PersianCalendar pc     = new PersianCalendar();
            var             nextm1 = pc.AddMonths(st1, 1);

            return(new DateTime(pc.GetYear(nextm1), pc.GetMonth(nextm1), 1, pc));//.AddSeconds(-1);
        }
Пример #3
0
        public static PersianDateTime AddMonths(this PersianDateTime persianDateTime, int months)
        {
            var dateTime = PersianCalendar.AddMonths(persianDateTime.DateTime, months);

            persianDateTime.DateTime = dateTime;
            return(new PersianDateTime(dateTime));
        }
Пример #4
0
    public static SqlString GTS_ASM_AddShamsiMonth(int Year, int Month, int Day, int Value)
    {
        string          ShamsiDate = String.Format("{0}/{1}/{2}", Year, Month, Day);
        PersianCalendar pc         = new PersianCalendar();
        DateTime        dt         = Convert.ToDateTime(GTS_ASM_ShamsiToMiladi(ShamsiDate).ToString());

        return(GTS_ASM_MiladiToShamsi(pc.AddMonths(dt, Value).ToShortDateString()).ToString());
    }
        public void Should_add_month_to_persian_date(string current, int months, string expected)
        {
            // Arrange
            // Act
            var final = persianCalendar.AddMonths(current, months);

            // Assert
            Assert.Equal(expected, final);
        }
Пример #6
0
        public Date AddMonths(int months)
        {
            if (IsEmpty(this))
            {
                throw new ArgumentException("Date is empty!");
            }

            return(new Date(PersianCalendar.AddMonths(dateGregorian, months)));
        }
        public static string AddMonths(this PersianCalendar persianCalendar, string persianDate, int months)
        {
            if (!IsValidDate(persianCalendar, persianDate))
            {
                throw new ArgumentException();
            }
            var init  = ConvertToGregorian(persianCalendar, persianDate);
            var final = persianCalendar.AddMonths(init, months);

            return(ConvertToPersian(persianCalendar, final));
        }
Пример #8
0
        public async Task <string> CountOfWebsiteViewIn12MonthsAgo()
        {
            var websiteViewIn12MonthsAgoList = new List <WebsiteViewIn12MonthsAgo>();
            var dateTimeNow         = DateTime.Now;
            var dateTime12MonthsAgo = dateTimeNow.AddMonths(-12);

            var persianCalendar            = new PersianCalendar();
            var year12Persian              = persianCalendar.GetYear(dateTime12MonthsAgo);
            var month12Persian             = persianCalendar.GetMonth(dateTime12MonthsAgo);
            var dateTime12MonthsClockClear = persianCalendar.ToDateTime(year12Persian, month12Persian, 1, 0, 0, 0, 0);

            var yearNowPersian        = persianCalendar.GetYear(dateTimeNow);
            var monthNowPersian       = persianCalendar.GetMonth(dateTimeNow);
            var dateTimeNowClockClear = persianCalendar.AddMonths(persianCalendar.ToDateTime(yearNowPersian, monthNowPersian, 1, 0, 0, 0, 0), 1);

            var websiteViews =
                _webView
                .AsNoTracking()
                .Where(q => q.CreatedOn <= dateTimeNowClockClear & q.CreatedOn >= dateTime12MonthsClockClear)
                .AsQueryable();

            var next = persianCalendar.ToDateTime(year12Persian, month12Persian, 1, 0, 0, 0, 0);

            while (next < dateTimeNowClockClear)
            {
                var nextmonth    = persianCalendar.AddMonths(next, 1);
                var next1        = next;
                var dailyWebView = await websiteViews.Where(q => q.CreatedOn <= nextmonth& q.CreatedOn >= next1).CountAsync();

                websiteViewIn12MonthsAgoList.Add(new WebsiteViewIn12MonthsAgo
                {
                    Month = next.ToPersianString("yyyy-MM"),
                    Count = dailyWebView
                });

                next = persianCalendar.AddMonths(next, 1);
            }

            return(JsonConvert.SerializeObject(websiteViewIn12MonthsAgoList, Formatting.None));
        }
Пример #9
0
        public static string getFirstSolarMonth(this DateTime value, int moveMonth = 0)
        {
            string today   = DateTime.Today.ToSolar();
            string toMonth = today.Substring(0, today.Length - 2) + "01";

            if (moveMonth == 0)
            {
                return(toMonth);
            }

            DateTime toMonthAD = Convert.ToDateTime(toMonth.ToAD());

            PersianCalendar pc = new PersianCalendar();

            return(pc.AddMonths(toMonthAD, moveMonth).ToSolar());
        }
Пример #10
0
        public async Task <HttpResponseMessage> SaveReservation([FromBody] ReservationVM reservationVM)
        {
            try
            {
                var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId);


                reservationVM.ReservationDetails = reservationVM.ReservationDetails.Where(x => x.Saze != null).ToList();

                foreach (var reservationDetailVM in reservationVM.ReservationDetails)
                {
                    if (reservationDetailVM.Saze != null)
                    {
                        reservationDetailVM.SazeID = reservationDetailVM.Saze.ID;
                    }

                    if (reservationDetailVM.NoeEjare != null)
                    {
                        reservationDetailVM.NoeEjareID = reservationDetailVM.NoeEjare.ID;
                    }

                    if (reservationDetailVM.StartDisplayDate != null)
                    {
                        reservationDetailVM.StartDate = PersianDateUtils.ToDateTime(reservationDetailVM.StartDisplayDate);
                    }

                    if (reservationDetailVM.NoeEjareID == 1)
                    {
                        reservationDetailVM.EndDate = reservationDetailVM.StartDate.AddDays((double)reservationDetailVM.Quantity - 1);
                    }
                    else if (reservationDetailVM.NoeEjareID == 2)
                    {
                        PersianCalendar pc = new PersianCalendar();
                        reservationDetailVM.EndDate = pc.AddMonths(reservationDetailVM.StartDate, (int)reservationDetailVM.Quantity);
                    }

                    reservationDetailVM.EndDisplayDate = PersianDateUtils.ToPersianDateTime(reservationDetailVM.EndDate);
                }


                if (reservationVM.Contact != null)
                {
                    reservationVM.ContactID = reservationVM.Contact.ID;
                }

                Reservation reservation = new Reservation();
                Mapper.Map(reservationVM, reservation);
                reservation.OrganID = organId;

                reservation.RegisterDate        = DateTime.Now;
                reservation.DisplayRegisterDate = PersianDateUtils.ToPersianDateTime(DateTime.Now);



                ReservationValidate validator = new ReservationValidate();
                FluentValidation.Results.ValidationResult results = validator.Validate(reservation);

                string failurs = "";

                if (!results.IsValid)
                {
                    foreach (var error in results.Errors)
                    {
                        failurs += "<br/>" + error.ErrorMessage;
                    }
                    return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = ZhivarEnums.ResultCode.ValidationError, data = failurs }));
                }

                foreach (var reservationDetailVM in reservationVM.ReservationDetails)
                {
                    using (var uow = new UnitOfWork())
                    {
                        reservationDetailVM.StartDate = PersianDateUtils.ToDateTime(reservationDetailVM.StartDisplayDate);

                        if (reservationDetailVM.NoeEjareID == 1)
                        {
                            reservationDetailVM.EndDate = reservationDetailVM.StartDate.AddDays((double)reservationDetailVM.Quantity);
                            reservationDetailVM.EndDate = reservationDetailVM.EndDate.AddDays(-1);
                        }
                        else if (reservationDetailVM.NoeEjareID == 2)
                        {
                            PersianCalendar pc = new PersianCalendar();
                            reservationDetailVM.EndDate = pc.AddMonths(reservationDetailVM.StartDate, (int)reservationDetailVM.Quantity);
                            reservationDetailVM.EndDate = reservationDetailVM.EndDate.AddDays(-1);
                        }

                        var contractsRentFromIds = await uow.RepositoryAsync <DomainClasses.Contract.Contract>().Queryable().Where(x => (x.ContractType == ContractType.RentFrom) && x.OrganId == organId).Select(x => x.ID).ToListAsync2();

                        var allSazesRentFrom = uow.RepositoryAsync <Contract_Saze>().Queryable().Where(x => contractsRentFromIds.Contains(x.ContractID) && x.SazeId == reservationDetailVM.SazeID &&
                                                                                                       ((x.TarikhShorou >= reservationDetailVM.StartDate.Date && x.TarikhShorou <= reservationDetailVM.EndDate.Date) ||
                                                                                                        (x.TarikhShorou <= reservationDetailVM.StartDate.Date && x.TarikhPayan >= reservationDetailVM.StartDate.Date) ||
                                                                                                        (x.TarikhShorou <= reservationDetailVM.StartDate.Date && x.TarikhPayan >= reservationDetailVM.StartDate.Date) ||
                                                                                                        (x.TarikhShorou >= reservationDetailVM.StartDate.Date && x.TarikhPayan <= reservationDetailVM.EndDate.Date)));

                        if (!await allSazesRentFrom.AnyAsync2())
                        {
                            string str = " این سازه از تاریخ " + reservationDetailVM.StartDisplayDate + " تا تاریخ " + PersianDateUtils.ToPersianDate(reservationDetailVM.EndDate) + " در اجاره شرکت نمی باشد. ";

                            return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = ZhivarEnums.ResultCode.ValidationError, data = str }));
                        }

                        var contractsIds = await uow.RepositoryAsync <DomainClasses.Contract.Contract>().Queryable().Where(x => (x.ContractType == ContractType.PreContract || x.ContractType == ContractType.RentTo) && x.OrganId == organId).Select(x => x.ID).ToListAsync2();

                        var allSazes = uow.RepositoryAsync <Contract_Saze>().Queryable().Where(x => contractsIds.Contains(x.ContractID) && x.SazeId == reservationDetailVM.SazeID &&
                                                                                               ((x.TarikhShorou >= reservationDetailVM.StartDate.Date && x.TarikhShorou <= reservationDetailVM.EndDate.Date) ||
                                                                                                (x.TarikhShorou <= reservationDetailVM.StartDate.Date && x.TarikhPayan >= reservationDetailVM.StartDate.Date) ||
                                                                                                (x.TarikhShorou <= reservationDetailVM.StartDate.Date && x.TarikhPayan >= reservationDetailVM.StartDate.Date) ||
                                                                                                (x.TarikhShorou >= reservationDetailVM.StartDate.Date && x.TarikhPayan <= reservationDetailVM.EndDate.Date)));

                        var contractStopDetails = uow.RepositoryAsync <ContractStopDetails>().Queryable().Where(x => x.SazeID == reservationDetailVM.SazeID &&
                                                                                                                x.StartDate <= reservationDetailVM.StartDate.Date && x.EndDate > reservationDetailVM.EndDate.Date);

                        //if (await contractStopDetails.AnyAsync2())
                        //    return Request.CreateResponse(HttpStatusCode.OK, new { resultCode = ZhivarEnums.ResultCode.Successful, data = "" });

                        if (await allSazes.AnyAsync2())
                        {
                            var p = await allSazes.FirstOrDefaultAsync2();

                            var contract = await uow.RepositoryAsync <DomainClasses.Contract.Contract>().Queryable().Where(x => x.ID == p.ContractID).SingleOrDefaultAsync2();

                            string noeEjareStr = "ماه";
                            if (p.NoeEjareId == 1)
                            {
                                noeEjareStr = "روز";
                            }
                            string str = " این سازه از تاریخ " + p.DisplayTarikhShorou + " به مدت " + ((int)p.Quantity).ToString() + " " + noeEjareStr + " در اجاره قرارداد شماره " + Convert.ToInt32(contract.Number).ToString() + " با عنوان " + contract.ContractTitle + " می باشد. ";
                            //string str = " می باشد. " + contract.ContactTitle + " با عنوان " + contract.Number + " در اجاره قرارداد شماره " + noeEjareStr + p.Quantity + " به مدت " + p.DisplayTarikhShorou + " این سازه از تاریخ ";
                            return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = ZhivarEnums.ResultCode.ValidationError, data = str }));
                        }
                        else
                        {
                            var reservationsIds = uow.RepositoryAsync <Reservation>().Queryable().Where(x => x.OrganID == organId).Select(x => x.ID).ToList();

                            var reservation_Details = uow.RepositoryAsync <Reservation_Detail>().Queryable().Where(x => reservationsIds.Contains(x.ReservationID) && x.SazeID == reservationDetailVM.SazeID &&
                                                                                                                   ((x.StartDate >= reservationDetailVM.StartDate.Date && x.StartDate <= reservationDetailVM.EndDate.Date) ||
                                                                                                                    (x.StartDate <= reservationDetailVM.StartDate.Date && x.EndDate >= reservationDetailVM.StartDate.Date) ||
                                                                                                                    (x.StartDate <= reservationDetailVM.StartDate.Date && x.EndDate >= reservationDetailVM.StartDate.Date) ||
                                                                                                                    (x.StartDate >= reservationDetailVM.StartDate.Date && x.EndDate <= reservationDetailVM.EndDate.Date)));

                            if (await reservation_Details.AnyAsync2())
                            {
                                var reservation_Detail = await reservation_Details.FirstOrDefaultAsync2();

                                var reservationTemp = await uow.RepositoryAsync <Reservation>().Queryable().Where(x => x.ID == reservation_Detail.ReservationID).SingleOrDefaultAsync2();

                                string noeEjareStr = "ماه";
                                if (reservation_Detail.NoeEjareID == 1)
                                {
                                    noeEjareStr = "روز";
                                }
                                string str = " این سازه از تاریخ " + reservation_Detail.StartDisplayDate + " به مدت " + ((int)reservation_Detail.Quantity).ToString() + " " + noeEjareStr + " رزرو می باشد. "; // + Convert.ToInt32(reservation.).ToString() + " با عنوان " + reservation. + " می باشد. ";
                                                                                                                                                                                                               //string str = " می باشد. " + contract.ContactTitle + " با عنوان " + contract.Number + " در اجاره قرارداد شماره " + noeEjareStr + p.Quantity + " به مدت " + p.DisplayTarikhShorou + " این سازه از تاریخ ";
                                return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = ZhivarEnums.ResultCode.ValidationError, data = str }));
                            }
                        }
                    }
                }



                if (reservation.ID > 0)
                {
                    foreach (var reservationDetail in reservation.ReservationDetails)
                    {
                        reservationDetail.StartDate     = PersianDateUtils.ToDateTime(reservationDetail.StartDisplayDate);
                        reservationDetail.ReservationID = reservation.ID;

                        if (reservationDetail.ID > 0)
                        {
                            reservationDetail.ReservationID = reservation.ID;
                            reservationDetail.ObjectState   = ObjectState.Modified;
                        }

                        else
                        {
                            reservationDetail.ReservationID = reservation.ID;
                            reservationDetail.ObjectState   = ObjectState.Added;
                        }
                    }

                    reservation.ObjectState = ObjectState.Modified;
                }

                else
                {
                    foreach (var reservationDetail in reservation.ReservationDetails)
                    {
                        reservationDetail.ReservationID = reservation.ID;
                        reservationDetail.StartDate     = PersianDateUtils.ToDateTime(reservationDetail.StartDisplayDate);

                        if (reservationDetail.ID > 0)
                        {
                            reservationDetail.ReservationID = reservation.ID;
                            reservationDetail.ObjectState   = ObjectState.Modified;
                        }

                        else
                        {
                            reservationDetail.ReservationID = reservation.ID;
                            reservationDetail.ObjectState   = ObjectState.Added;
                        }
                    }


                    reservation.ObjectState = ObjectState.Added;
                }


                this.BusinessRule.UnitOfWork.RepositoryAsync <Reservation>().InsertOrUpdateGraph(reservation);

                await this.BusinessRule.UnitOfWork.SaveChangesAsync();


                return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = ZhivarEnums.ResultCode.Successful, data = reservation }));
            }
            catch (Exception ex)
            {
                var p = ex;
                throw;
            }
        }
 /// <summary>
 /// اضافه کردن ماه به تاریخ
 /// </summary>
 public PersianDateTime AddMonths(int months)
 {
     return(new PersianDateTime(PersianCalendar.AddMonths(_dateTime, months), EnglishNumber));
 }
Пример #12
0
 public PersianDateTime AddMonths(int months)
 {
     return(new PersianDateTime(persianCalendar.AddMonths(this.dateTime, months)));
 }
 public PersianDateTime AddMonths(int monthes)
 {
     return(PersianDateTime.FromGorgian(Calendar.AddMonths(DateTime, monthes)));
 }
Пример #14
0
 public PersianDate AddMonths(int months)
 {
     return(new PersianDate(_pc.AddMonths(_date, months)));
 }
Пример #15
0
 public static DateTime FaAddMonths(this DateTime src, int value)
 {
     return(PersianCalendar.AddMonths(src, value));
 }
Пример #16
0
        static public DateTime PCAddMonths(DateTime st1, int n)
        {
            PersianCalendar pc = new PersianCalendar();

            return(pc.AddMonths(st1, n));
        }
Пример #17
0
        public async Task <List <string> > SaveContract(ContractVM contractVM)
        {
            try
            {
                var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId);

                FinanYearRule finanYearRule = new FinanYearRule();
                var           finanYears    = await finanYearRule.GetAllByOrganIdAsync(organId);

                var finanYear = finanYears.Where(x => x.Closed == false && x.OrganId == organId);

                contractVM.Contract_Sazes = contractVM.Contract_Sazes.Where(x => x.Saze != null).ToList();

                foreach (var contract_Saze in contractVM.Contract_Sazes)
                {
                    if (contract_Saze.Saze != null)
                    {
                        contract_Saze.SazeId = contract_Saze.Saze.ID;
                    }

                    if (contract_Saze.NoeEjare != null)
                    {
                        contract_Saze.NoeEjareId = contract_Saze.NoeEjare.ID;
                    }

                    if (contract_Saze.DisplayTarikhShorou != null)
                    {
                        contract_Saze.TarikhShorou = PersianDateUtils.ToDateTime(contract_Saze.DisplayTarikhShorou);



                        if (contract_Saze.NoeEjareId == 1)
                        {
                            contract_Saze.TarikhPayan = contract_Saze.TarikhShorou.AddDays((double)contract_Saze.Quantity);
                        }
                        else if (contract_Saze.NoeEjareId == 2)
                        {
                            PersianCalendar pc = new PersianCalendar();
                            contract_Saze.TarikhPayan        = pc.AddMonths(contract_Saze.TarikhShorou, (int)contract_Saze.Quantity);
                            contract_Saze.DisplayTarikhPayan = PersianDateUtils.ToPersianDate(contract_Saze.TarikhPayan);
                        }
                    }
                }

                if (contractVM.Contact != null)
                {
                    contractVM.ContactId = contractVM.Contact.ID;
                }

                DomainClasses.Contract.Contract contract = new DomainClasses.Contract.Contract();
                Mapper.Map(contractVM, contract);
                contract.OrganId  = organId;
                contract.DateTime = PersianDateUtils.ToDateTime(contract.DisplayDate);


                ContractValidate validator = new ContractValidate();
                FluentValidation.Results.ValidationResult results = validator.Validate(contract);

                List <string> failurs = new List <string>();;

                if (!results.IsValid)
                {
                    foreach (var error in results.Errors)
                    {
                        failurs.Add(error.ErrorMessage);
                    }
                    return(failurs);
                }

                //  contract = savePaymentForContract(contract, contractVM);
                if (SecurityManager.CurrentUserContext.Roles.Any(x => x.RoleCode == "Manager") &&
                    contractVM.ContractType == ContractType.RentFrom)
                {
                    contract.Status = Status.ConfirmationContract;
                }
                else if (SecurityManager.CurrentUserContext.Roles.Any(x => x.RoleCode == "Manager") &&
                         contractVM.ContractType == ContractType.PreContract)
                {
                    contract.Status = Status.ConfirmationPreContract;

                    contract.ContractType = ContractType.RentTo;

                    // contract.Contract_Sazes = uow.Repository<Contract_Saze>().Queryable().Where(x => x.ContractID == contract.ID).ToList();

                    foreach (var contract_Saze in contract.Contract_Sazes ?? new List <Contract_Saze>())
                    {
                        contract_Saze.Status = Status.ConfirmationPreContract;
                        //contract_Saze.ObjectState = OMF.Common.Enums.ObjectState.Modified;
                    }
                }
                else if (contractVM.ContractType == ContractType.PreContract && contractVM.Status == Status.SendPreContract)
                {
                    //nothing
                }
                else
                {
                    contract.Status = Status.Temporary;
                }

                if (contract.ID > 0)
                {
                    foreach (var contractSaze in contract.Contract_Sazes)
                    {
                        contractSaze.TarikhShorou = PersianDateUtils.ToDateTime(contractSaze.DisplayTarikhShorou);
                        contractSaze.ContractID   = contract.ID;

                        if (contractSaze.ID > 0)
                        {
                            contractSaze.ContractID  = contract.ID;
                            contractSaze.ObjectState = OMF.Common.Enums.ObjectState.Modified;
                        }

                        else
                        {
                            contractSaze.ContractID  = contract.ID;
                            contractSaze.ObjectState = OMF.Common.Enums.ObjectState.Added;
                        }


                        foreach (var contarct_Saze_Bazareab in contractSaze.Contarct_Saze_Bazareabs)
                        {
                            contractSaze.HasBazareab = true;
                            if (contarct_Saze_Bazareab.ID > 0)
                            {
                                contarct_Saze_Bazareab.ContarctSazeID = contractSaze.ID;
                                contarct_Saze_Bazareab.ObjectState    = ObjectState.Modified;
                            }
                            else
                            {
                                contarct_Saze_Bazareab.ContarctSazeID = contractSaze.ID;
                                contarct_Saze_Bazareab.ObjectState    = ObjectState.Added;
                            }
                        }

                        foreach (var contract_Saze_Tarah in contractSaze.Contract_Saze_Tarahs)
                        {
                            contractSaze.HasTarah = true;

                            if (contract_Saze_Tarah.ID > 0)
                            {
                                contract_Saze_Tarah.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Tarah.ObjectState    = ObjectState.Modified;
                            }

                            else
                            {
                                contract_Saze_Tarah.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Tarah.ObjectState    = ObjectState.Added;
                            }
                        }

                        foreach (var contract_Saze_Chapkhane in contractSaze.Contract_Saze_Chapkhanes)
                        {
                            contractSaze.HasChap = true;

                            if (contract_Saze_Chapkhane.ID > 0)
                            {
                                contract_Saze_Chapkhane.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Chapkhane.ObjectState    = ObjectState.Modified;
                            }

                            else
                            {
                                contract_Saze_Chapkhane.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Chapkhane.ObjectState    = ObjectState.Added;
                            }
                        }

                        foreach (var contract_Saze_Nasab in contractSaze.Contract_Saze_Nasabs)
                        {
                            contractSaze.HasNasab = true;
                            if (contract_Saze_Nasab.ID > 0)
                            {
                                contract_Saze_Nasab.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Nasab.ObjectState    = ObjectState.Modified;
                            }

                            else
                            {
                                contract_Saze_Nasab.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Nasab.ObjectState    = ObjectState.Added;
                            }
                        }
                    }


                    foreach (var contract_PayRecevie in contract.Contract_PayRecevies)
                    {
                        if (contract_PayRecevie.ID > 0)
                        {
                            contract_PayRecevie.ContractId  = contract.ID;
                            contract_PayRecevie.ObjectState = OMF.Common.Enums.ObjectState.Modified;
                        }

                        else
                        {
                            contract_PayRecevie.ContractId = contract.ID;
                            contract_PayRecevie.IsReceive  = true;
                            contract_PayRecevie.OrganId    = organId;
                            contract_PayRecevie.Status     = Status.Temporary;
                            contract_PayRecevie.Type       = PayRecevieType.Sir;
                            contract_PayRecevie.Date       = DateTime.Now;

                            contract_PayRecevie.ContactId   = contract.ID;
                            contract_PayRecevie.ObjectState = OMF.Common.Enums.ObjectState.Added;
                        }


                        foreach (var contract_DetailPayRecevie in contract_PayRecevie.Contract_DetailPayRecevies)
                        {
                            if (contract_DetailPayRecevie.ID > 0)
                            {
                                contract_DetailPayRecevie.Contract_PayRecevieId = contract_PayRecevie.ID;
                                contract_DetailPayRecevie.ObjectState           = ObjectState.Modified;
                            }
                            else
                            {
                                contract_DetailPayRecevie.Contract_PayRecevieId = contract_PayRecevie.ID;
                                contract_DetailPayRecevie.ObjectState           = ObjectState.Added;
                            }
                        }
                    }
                    contract.ObjectState = OMF.Common.Enums.ObjectState.Modified;
                }

                else
                {
                    foreach (var contractSaze in contract.Contract_Sazes)
                    {
                        contractSaze.ContractID   = contract.ID;
                        contractSaze.TarikhShorou = PersianDateUtils.ToDateTime(contractSaze.DisplayTarikhShorou);

                        if (contractSaze.ID > 0)
                        {
                            contractSaze.ContractID  = contract.ID;
                            contractSaze.ObjectState = OMF.Common.Enums.ObjectState.Modified;
                        }

                        else
                        {
                            contractSaze.ContractID  = contract.ID;
                            contractSaze.ObjectState = OMF.Common.Enums.ObjectState.Added;
                        }


                        foreach (var contarct_Saze_Bazareab in contractSaze.Contarct_Saze_Bazareabs)
                        {
                            contractSaze.HasBazareab = true;

                            if (contarct_Saze_Bazareab.NoeMozdBazryab == NoeMozd.Month)
                            {
                                contarct_Saze_Bazareab.Hazine = 0;
                            }

                            if (contarct_Saze_Bazareab.ID > 0)
                            {
                                contarct_Saze_Bazareab.ContarctSazeID = contractSaze.ID;
                                contarct_Saze_Bazareab.ObjectState    = ObjectState.Modified;
                            }
                            else
                            {
                                contarct_Saze_Bazareab.ContarctSazeID = contractSaze.ID;
                                contarct_Saze_Bazareab.ObjectState    = ObjectState.Added;
                            }
                        }

                        foreach (var contract_Saze_Tarah in contractSaze.Contract_Saze_Tarahs)
                        {
                            contractSaze.HasTarah = true;

                            if (contract_Saze_Tarah.NoeMozdTarah == NoeMozd.Month)
                            {
                                contract_Saze_Tarah.Hazine = 0;
                            }

                            if (contract_Saze_Tarah.ID > 0)
                            {
                                contract_Saze_Tarah.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Tarah.ObjectState    = ObjectState.Modified;
                            }

                            else
                            {
                                contract_Saze_Tarah.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Tarah.ObjectState    = ObjectState.Added;
                            }
                        }

                        foreach (var contract_Saze_Chapkhane in contractSaze.Contract_Saze_Chapkhanes)
                        {
                            contractSaze.HasChap = true;



                            if (contract_Saze_Chapkhane.ID > 0)
                            {
                                contract_Saze_Chapkhane.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Chapkhane.ObjectState    = ObjectState.Modified;
                            }

                            else
                            {
                                contract_Saze_Chapkhane.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Chapkhane.ObjectState    = ObjectState.Added;
                            }
                        }

                        foreach (var contract_Saze_Nasab in contractSaze.Contract_Saze_Nasabs)
                        {
                            contractSaze.HasNasab = true;

                            if (contract_Saze_Nasab.NoeMozdNasab == NoeMozd.Month)
                            {
                                contract_Saze_Nasab.Hazine = 0;
                            }

                            if (contract_Saze_Nasab.ID > 0)
                            {
                                contract_Saze_Nasab.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Nasab.ObjectState    = ObjectState.Modified;
                            }

                            else
                            {
                                contract_Saze_Nasab.ContarctSazeID = contractSaze.ID;
                                contract_Saze_Nasab.ObjectState    = ObjectState.Added;
                            }
                        }
                    }

                    if (contract.Contract_PayRecevies != null && contract.Contract_PayRecevies.Count() > 0 &&
                        contract.Contract_PayRecevies[0].Contract_DetailPayRecevies != null && contract.Contract_PayRecevies[0].Contract_DetailPayRecevies.Count() > 0)
                    {
                        foreach (var contract_PayRecevie in contract.Contract_PayRecevies)
                        {
                            contract_PayRecevie.ContractId = contract.ID;
                            contract_PayRecevie.Date       = DateTime.Now;
                            contract_PayRecevie.IsReceive  = true;


                            if (contract_PayRecevie.ID > 0)
                            {
                                contract_PayRecevie.ContractId  = contract.ID;
                                contract_PayRecevie.ObjectState = OMF.Common.Enums.ObjectState.Modified;
                            }

                            else
                            {
                                contract_PayRecevie.ContractId  = contract.ID;
                                contract_PayRecevie.ObjectState = OMF.Common.Enums.ObjectState.Added;
                            }


                            foreach (var contract_DetailPayRecevie in contract_PayRecevie.Contract_DetailPayRecevies)
                            {
                                if (contract_DetailPayRecevie.ID > 0)
                                {
                                    contract_DetailPayRecevie.Contract_PayRecevieId = contract_PayRecevie.ID;
                                    contract_DetailPayRecevie.ObjectState           = ObjectState.Modified;
                                }
                                else
                                {
                                    contract_DetailPayRecevie.Contract_PayRecevieId = contract_PayRecevie.ID;
                                    contract_DetailPayRecevie.ObjectState           = ObjectState.Added;
                                }
                            }
                        }
                    }
                    else
                    {
                        contract.Contract_PayRecevies = null;
                    }
                    contract.ObjectState = OMF.Common.Enums.ObjectState.Added;
                }


                this.UnitOfWork.RepositoryAsync <DomainClasses.Contract.Contract>().InsertOrUpdateGraph(contract);



                //  ContactRule contactRule = new ContactRule();
                //   await contactRule.UpdateContact(invoice.InvoiceType, invoice.ContactId);



                await this.UnitOfWork.SaveChangesAsync();

                if (contractVM.ID <= 0)
                {
                    if ((SecurityManager.CurrentUserContext.Roles.Any(x => x.RoleCode == "Manager") &&
                         contractVM.ContractType == ContractType.PreContract) || (SecurityManager.CurrentUserContext.Roles.Any(x => x.RoleCode == "Manager") &&
                                                                                  contractVM.Status == Status.ConfirmationContract))
                    {
                        InvoiceRule invoiceRule = new InvoiceRule();
                        var         invoice     = invoiceRule.ConvertContractToInvoice(contract.ID, NoeFactor.RentTo);

                        var document = invoiceRule.RegisterDocument(invoice, invoice.OrganId);

                        DocumentRule documentRule = new DocumentRule();
                        await documentRule.InsertAsync(document, invoice.OrganId);

                        await documentRule.SaveChangesAsync();

                        invoice.DocumentID = document.ID;
                        invoiceRule.Update(invoice);
                        await invoiceRule.SaveChangesAsync();
                    }
                    else if (SecurityManager.CurrentUserContext.Roles.Any(x => x.RoleCode == "Manager") &&
                             contractVM.ContractType == ContractType.RentTo)
                    {
                        InvoiceRule invoiceRule = new InvoiceRule();
                        invoiceRule.ConvertContractToInvoice(contract.ID, NoeFactor.RentFrom);
                    }
                }



                return(failurs);
            }
            catch (Exception ex)
            {
                var p = ex;
                throw;
            }
        }