public IEnumerable <WorkHourOnProjecstJson> GetThisPeriodProjectsByUserId(GetThisMonthDataByUserJson json)
        {
            List <WorkHourOnProjecstJson> result     = new List <WorkHourOnProjecstJson>();
            UnitOfWork           uow                 = new UnitOfWork();
            UserManager          userManager         = new UserManager(uow);
            TimeSheetManager     timeSheetManager    = new TimeSheetManager(uow);
            DisplayPeriodManager displayPeriodMnager = new DisplayPeriodManager(uow);
            User          currUser      = userManager.GetByID(Guid.Parse(json.userid));
            DisplayPeriod displayPeriod = displayPeriodMnager.GetDisplayPeriod(currUser);

            DateTime fromDate = json.values[0].Date;
            DateTime toDate   = json.values[json.values.Count() - 1].Date;

            var all = timeSheetManager.GetWorkHoursByUser(currUser, fromDate, toDate);

            foreach (var item in all.GroupBy(x => x.ProjectId).Select(y => y.FirstOrDefault()).ToList())
            {
                var addItem = new WorkHourOnProjecstJson();
                addItem.ProjectId = item.ProjectId;
                addItem.Title     = item.Project.Title;
                var hour = all.Where(a => a.ProjectId == item.ProjectId).Sum(d => d.Hours);
                addItem.Hour = DateUtility.ConvertToTimeSpan(hour);
                result.Add(addItem);
            }

            return(result);
        }
        public IEnumerable <TimeSheetJson> GetTimeSheetsByUserIdForFirstTime(Guid userID)
        {
            List <TimeSheetJson> result              = new List <TimeSheetJson>();
            UnitOfWork           uow                 = new UnitOfWork();
            UserManager          userManager         = new UserManager(uow);
            ProjectManager       projectManager      = new Domain.ProjectManager(uow);
            TimeSheetManager     timeSheetManager    = new TimeSheetManager(uow);
            DisplayPeriodManager displayPeriodMnager = new DisplayPeriodManager(uow);
            User          currentUser                = new UserHelper().GetCurrent();
            User          user          = userManager.GetByID(userID);
            DisplayPeriod displayPeriod = displayPeriodMnager.GetDisplayPeriod(currentUser);



            DateTime fromDate = DateTime.Now.AddDays(-7);
            DateTime toDate   = DateTime.Now;



            if (displayPeriod.IsWeekly)
            {
                fromDate = DateTime.Today.StartOfWeek(DayOfWeek.Saturday);
                toDate   = DateTime.Today.EndOfWeek(DayOfWeek.Friday);
            }
            else
            {
                toDate = fromDate.AddDays(displayPeriod.NumOfDays);
            }

            IEnumerable <WorkHour>     workHours = timeSheetManager.GetWorkHoursByUser(user, fromDate, toDate);
            IEnumerable <PresenceHour> presHours = timeSheetManager.GetPresHoursByUser(user, fromDate, toDate);

            result = TimeSheetAssembler.ToJsonsForConfirm(presHours, workHours, user);
            return(result);
        }
        private async Task ChoosePeriod()
        {
            var response = await _pageService.DisplayActionSheet("Choose Time Period", "Cancel", null,
                                                                 "Day", "Week", "Month", "Year", "All");

            switch (response)
            {
            case "Day":
                DisplayPeriod.ChooseNewPeriod(PeriodType.Day);
                break;

            case "Week":
                DisplayPeriod.ChooseNewPeriod(PeriodType.Week);
                break;

            case "Month":
                DisplayPeriod.ChooseNewPeriod(PeriodType.Month);
                break;

            case "Year":
                DisplayPeriod.ChooseNewPeriod(PeriodType.Year);
                break;

            case "All":
                DisplayPeriod.ChooseNewPeriod(PeriodType.All);
                break;
            }
            MessagingCenter.Send(this, MessagingString.UpdatePeriod);
        }
        ///// <summary>
        ///// بدست آوردن دوره های نمایش بر اساس شناسه کارمند
        ///// </summary>
        ///// <param name="employeeID">شناسه کارمند</param>
        ///// <returns>دوره های نمایش که در بررسی پایگاه داده بدست می آید.</returns>
        //public IEnumerable<DisplayPeriod> GetByEpmloyeeID(Guid employeeID)
        //{
        //    return _RASContext.DisplayPeriods.Where(ph => ph.EmployeeID.Equals(employeeID));
        //}

        /// <summary>
        /// اضافه کردن دوره نمایش جدید به پایگاه داده
        /// </summary>
        /// <param name="DisplayPeriod">موجودیت مرتبط با دوره نمایش جدید</param>
        public void Add(DisplayPeriod DisplayPeriod)
        {
            if (DisplayPeriod.ID == Guid.Empty)
            {
                DisplayPeriod.ID = Guid.NewGuid();
            }
            _RASContext.DisplayPeriods.Add(DisplayPeriod);
        }
 public void FillEntity(DisplayPeriod entity, DisplayPeriod displayPeriod)
 {
     entity.EmployeeID = displayPeriod.EmployeeID;
     entity.ID         = displayPeriod.ID;
     entity.IsWeekly   = displayPeriod.IsWeekly;
     entity.NumOfDays  = displayPeriod.NumOfDays;
     entity.StartDate  = displayPeriod.StartDate;
 }
Beispiel #6
0
        public static DisplayPeriod ConvertPeriodNumberDateJsonToDisplayPeriod(PeriodNumberDateJson json, IUnitOfWork uow, User currUser)
        {
            DisplayPeriodManager dpm         = new DisplayPeriodManager(uow);
            UserManager          userManager = new UserManager(uow);
            DisplayPeriod        result      = new DisplayPeriod();

            result           = dpm.GetDisplayPeriod(currUser);
            result.IsWeekly  = json.IsWeekly;
            result.NumOfDays = json.Days;
            result.StartDate = DateUtility.GetMiladiDate(json.Date);
            return(result);
        }
        public IEnumerable <TimeSheetJson> ChangeDisplayPeriodToWeekly()
        {
            UnitOfWork           uow         = new UnitOfWork();
            UserManager          um          = new UserManager(uow);
            var                  currentUser = new UserHelper().GetCurrent();
            DisplayPeriodManager dpm         = new DisplayPeriodManager(uow);
            DisplayPeriod        dp          = new DisplayPeriod();

            dp          = dpm.GetDisplayPeriod(currentUser);
            dp.IsWeekly = true;
            dpm.Edit(dp);
            return(GetTimeSheets());
        }
        public AllEntityJson GetThisPeriodData(List <TimeSheetValueJson> workHourJsons)
        {
            UnitOfWork           uow                 = new UnitOfWork();
            User                 currUser            = new UserHelper().GetCurrent();
            TimeSheetManager     timesheetManager    = new Domain.TimeSheetManager(uow);
            DisplayPeriodManager displayPeriodMnager = new DisplayPeriodManager(uow);
            DisplayPeriod        displayPeriod       = displayPeriodMnager.GetDisplayPeriod(currUser);
            DateTime             fromDate            = workHourJsons[0].Date;
            DateTime             toDate              = workHourJsons[workHourJsons.Count() - 1].Date;
            var presenceours = timesheetManager.GetThisPeriodPresencHoursByUserId(currUser.ID, fromDate, toDate);
            var workours     = timesheetManager.GetThisPeriodhworkHoursByUserId(currUser.ID, fromDate, toDate);

            return(new HomeEntityAssembler().ToJson(presenceours, workours));
        }
        public IEnumerable <TimeSheetJson> GetPreviousPeriod(WorkHourJson workHourJson)
        {
            List <TimeSheetJson> result = new List <TimeSheetJson>();

            if (workHourJson == null)
            {
                workHourJson      = new WorkHourJson();
                workHourJson.Date = DateTime.Now;
            }
            var                  startDate           = workHourJson.Date;
            UnitOfWork           uow                 = new UnitOfWork();
            UserManager          userManager         = new UserManager(uow);
            ProjectManager       projectManager      = new Domain.ProjectManager(uow);
            TimeSheetManager     timeSheetManager    = new TimeSheetManager(uow);
            DisplayPeriodManager displayPeriodMnager = new DisplayPeriodManager(uow);
            //SyncWithPWA(uow);
            User          currUser      = new UserHelper().GetCurrent();
            DisplayPeriod displayPeriod = displayPeriodMnager.GetDisplayPeriod(currUser);

            var dt = startDate.AddDays(-1);

            DateTime fromDate = dt.AddDays(-displayPeriod.NumOfDays);
            DateTime toDate   = dt;

            if (displayPeriod.IsWeekly)
            {
                fromDate = dt.StartOfWeek(DayOfWeek.Saturday);
                toDate   = dt.EndOfWeek(DayOfWeek.Friday);

                IEnumerable <PresenceHour> presHours = timeSheetManager.GetPresHoursByUser(currUser, fromDate, toDate);
                IEnumerable <WorkHour>     workHours = timeSheetManager.GetWorkHoursByUser(currUser, fromDate, toDate);
                result = TimeSheetAssembler.ToJsonsForRegister(presHours, workHours);
            }
            else
            {
                IEnumerable <PresenceHour> presHours = timeSheetManager.GetPresHoursByUser(currUser, fromDate, toDate);
                IEnumerable <WorkHour>     workHours = timeSheetManager.GetWorkHoursByUser(currUser, fromDate, toDate);
                if (presHours.Count() < displayPeriod.NumOfDays)
                {
                    fromDate  = timeSheetManager.GetFirstPresenceHour().Date;
                    toDate    = fromDate.AddDays(displayPeriod.NumOfDays);
                    presHours = timeSheetManager.GetPresHoursByUser(currUser, fromDate, toDate);
                }
                result = TimeSheetAssembler.ToJsonsForRegister(presHours, workHours);
            }



            return(result);
        }
Beispiel #10
0
        public async Task <IActionResult> GetPreviousPeriodConfirm(string ver, string type, Guid?userId, DateTime date)
        {
            UserManager          userManager         = new UserManager(this._uow);
            TimeSheetManager     timeSheetManager    = new TimeSheetManager(this._uow);
            DisplayPeriodManager displayPeriodMnager = new DisplayPeriodManager(this._uow);
            //SyncWithPWA(uow);
            User          currUser      = new UserHelper().GetCurrent(this._uow, this.UserName);
            DisplayPeriod displayPeriod = displayPeriodMnager.GetDisplayPeriod(currUser);

            DateTime fromDate;
            DateTime toDate;
            DateTime dt;

            if (type == "previous")
            {
                dt = date.AddDays(-1);

                fromDate = dt.AddDays(-displayPeriod.NumOfDays);
                toDate   = dt;
            }
            else
            {
                dt = date.AddDays(1);

                fromDate = dt;
                toDate   = dt.AddDays(displayPeriod.NumOfDays);
            }


            if (displayPeriod.IsWeekly)
            {
                fromDate = dt.StartOfWeek(DayOfWeek.Saturday);
                toDate   = dt.EndOfWeek(DayOfWeek.Friday);
            }
            else
            {
                IEnumerable <PresenceHour> presHours = timeSheetManager.GetPresHoursByUser(currUser, fromDate, toDate);
                if (presHours.Count() < displayPeriod.NumOfDays)
                {
                    fromDate = timeSheetManager.GetFirstPresenceHour().Date;
                    toDate   = fromDate.AddDays(displayPeriod.NumOfDays);
                }
            }

            return(await GetTimeSheet(ver, userId, fromDate, toDate));
        }
        public AllEntityJson GetThisPeriodDataByUserId(GetThisMonthDataByUserJson json)
        {
            UnitOfWork           uow                 = new UnitOfWork();
            UserManager          userManager         = new UserManager(uow);
            User                 currUser            = userManager.GetByID(Guid.Parse(json.userid));
            TimeSheetManager     timesheetManager    = new Domain.TimeSheetManager(uow);
            DisplayPeriodManager displayPeriodMnager = new DisplayPeriodManager(uow);
            DisplayPeriod        displayPeriod       = displayPeriodMnager.GetDisplayPeriod(currUser);

            DateTime fromDate = json.values[0].Date;
            DateTime toDate   = json.values[json.values.Count() - 1].Date;

            var presenceours = timesheetManager.GetThisPeriodPresencHoursByUserId(currUser.ID, fromDate, toDate);
            var workours     = timesheetManager.GetThisPeriodhworkHoursByUserId(currUser.ID, fromDate, toDate);

            return(new HomeEntityAssembler().ToJson(presenceours, workours));
        }
Beispiel #12
0
        public IActionResult ChangeDisplayPeriodToWeeklyConfirm()
        {
            try
            {
                var currentUser          = new UserHelper().GetCurrent(this._uow, this.UserName);
                DisplayPeriodManager dpm = new DisplayPeriodManager(this._uow);
                DisplayPeriod        dp  = new DisplayPeriod();
                dp          = dpm.GetDisplayPeriod(currentUser);
                dp.IsWeekly = true;
                dpm.Edit(dp);

                return(Ok(true));
            }
            catch (Exception ex)
            {
                return(this.ReturnError(ex, "خطا در تغییر به هفتگی"));
            }
        }
        public IEnumerable <TimeSheetJson> ChangeDisplayPeriodToWeeklyConfirm(Guid UserId)
        {
            UnitOfWork  uow  = new UnitOfWork();
            UserManager um   = new UserManager(uow);
            var         user = um.GetByID(UserId);

            var currentUser          = new UserHelper().GetCurrent();
            DisplayPeriodManager dpm = new DisplayPeriodManager(uow);
            DisplayPeriod        dp  = new DisplayPeriod();

            dp          = dpm.GetDisplayPeriod(currentUser);
            dp.IsWeekly = true;
            dpm.Edit(dp);
            var inputArg = new GetThisMonthDataByUserJson();

            inputArg.userid = user.ID.ToString();
            return(GetTimeSheetsByUserId(inputArg));
        }
        public IEnumerable <TimeSheetJson> GetTimeSheetsByUserId(GetThisMonthDataByUserJson json)
        {
            List <TimeSheetJson> result              = new List <TimeSheetJson>();
            UnitOfWork           uow                 = new UnitOfWork();
            UserManager          userManager         = new UserManager(uow);
            ProjectManager       projectManager      = new Domain.ProjectManager(uow);
            TimeSheetManager     timeSheetManager    = new TimeSheetManager(uow);
            DisplayPeriodManager displayPeriodMnager = new DisplayPeriodManager(uow);
            User          currentUser                = new UserHelper().GetCurrent();
            User          user          = userManager.GetByID(Guid.Parse(json.userid.ToString()));
            DisplayPeriod displayPeriod = displayPeriodMnager.GetDisplayPeriod(currentUser);
            DateTime      fromDate      = DateTime.Now.AddDays(-7);
            DateTime      toDate;

            if (json.values != null)
            {
                if (json.values.Count > 0)
                {
                    fromDate = json.values[0].Date;
                    toDate   = json.values[json.values.Count() - 1].Date;
                }
            }


            if (displayPeriod.IsWeekly)
            {
                fromDate = DateTime.Today.StartOfWeek(DayOfWeek.Saturday);
                toDate   = DateTime.Today.EndOfWeek(DayOfWeek.Friday);
            }
            else
            {
                toDate = fromDate.AddDays(displayPeriod.NumOfDays);
            }

            IEnumerable <WorkHour>     workHours = timeSheetManager.GetWorkHoursByUser(user, fromDate, toDate);
            IEnumerable <PresenceHour> presHours = timeSheetManager.GetPresHoursByUser(user, fromDate, toDate);

            result = TimeSheetAssembler.ToJsonsForConfirm(presHours, workHours, user);
            return(result);
        }
        public IEnumerable <TimeSheetJson> GetTimeSheets()
        {
            List <TimeSheetJson> result              = new List <TimeSheetJson>();
            UnitOfWork           uow                 = new UnitOfWork();
            UserManager          userManager         = new UserManager(uow);
            ProjectManager       projectManager      = new Domain.ProjectManager(uow);
            TimeSheetManager     timeSheetManager    = new TimeSheetManager(uow);
            DisplayPeriodManager displayPeriodMnager = new DisplayPeriodManager(uow);
            User          currUser = new UserHelper().GetCurrent();
            DateTime      fromDate;
            DateTime      toDate        = DateTime.MaxValue;
            DisplayPeriod displayPeriod = displayPeriodMnager.GetDisplayPeriod(currUser);

            if (displayPeriod != null)
            {
                fromDate = displayPeriod.StartDate;
                if (displayPeriod.IsWeekly)
                {
                    fromDate = DateTime.Today.StartOfWeek(DayOfWeek.Saturday);
                    toDate   = DateTime.Today.EndOfWeek(DayOfWeek.Friday);
                }
                else
                {
                    toDate = fromDate.AddDays(displayPeriod.NumOfDays);
                }
            }
            else
            {
                fromDate = DateTime.Today.StartOfWeek(DayOfWeek.Saturday);
                toDate   = DateTime.Today.EndOfWeek(DayOfWeek.Friday);
            }
            IEnumerable <WorkHour>     workHours = timeSheetManager.GetWorkHoursByUser(currUser, fromDate, toDate);
            IEnumerable <PresenceHour> presHours = timeSheetManager.GetPresHoursByUser(currUser, fromDate, toDate);

            result = TimeSheetAssembler.ToJsonsForRegister(presHours, workHours);
            return(result);
        }
 private void NextTimePeriod()
 {
     DisplayPeriod.MoveToNext();
     MessagingCenter.Send(this, MessagingString.UpdatePeriod);
 }
 private void PreviousTimePeriod()
 {
     DisplayPeriod.MoveToPrevious();
     MessagingCenter.Send(this, MessagingString.UpdatePeriod);
 }
 private void ResetTimePeriod(object obj)
 {
     DisplayPeriod.ResetSelectedDate(DateTime.Now);
     MessagingCenter.Send(this, MessagingString.UpdatePeriod);
 }
 private async Task SetDate(object newDate)
 {
     DisplayPeriod.ResetSelectedDate((DateTime)newDate);
     MessagingCenter.Send(this, MessagingString.UpdatePeriod);
 }
Beispiel #20
0
        public async Task <IActionResult> GetTimeSheet(string ver, Guid?userId, DateTime?fromDate, DateTime?toDate)
        {
            var isWantingApprove = userId.HasValue;

            try
            {
                if (!this.MainChecks(ver, out string error))
                {
                    throw new Exception(error);
                }

                DisplayPeriodManager displayPeriodMnager = new DisplayPeriodManager(this._uow);
                User currentUser = new UserHelper().GetCurrent(this._uow, this.UserName);

                if (!fromDate.HasValue)
                {
                    DisplayPeriod displayPeriod = displayPeriodMnager.GetDisplayPeriod(currentUser);


                    if (!fromDate.HasValue)
                    {
                        fromDate = DateTime.Now.AddDays(-7);
                    }
                    if (!toDate.HasValue)
                    {
                        toDate = DateTime.Now;
                    }

                    if (displayPeriod.IsWeekly)
                    {
                        fromDate = DateTime.Today.StartOfWeek(DayOfWeek.Saturday);
                        toDate   = DateTime.Today.EndOfWeek(DayOfWeek.Friday);
                    }
                    else
                    {
                        toDate = fromDate.Value.AddDays(displayPeriod.NumOfDays);
                    }
                }

                var mustCheckDefaultTimeSheetPolocy = false;
                var now = DateTime.Now;
                mustCheckDefaultTimeSheetPolocy = now >= fromDate && now <= toDate;

                var numberOfReset = -1;

labelForReset:

                numberOfReset++;

                IQueryable <Persistance.QueryEntities.EmployeeTimeSheetFromDB> query = null;

                if (isWantingApprove)
                {
                    query = this.DBContext.spFoundConfirmTimeSheet.FromSqlInterpolated(this.DBContext.spFoundConfirmTimeSheet_str(
                                                                                           currentUser.ID,
                                                                                           userId,
                                                                                           fromDate.Value,
                                                                                           toDate.Value
                                                                                           ));
                }
                else
                {
                    query = this.DBContext.spFoundConfirmTimeSheet.FromSqlInterpolated(this.DBContext.spFoundEmployeeTimeSheet_str(
                                                                                           currentUser.ID,
                                                                                           fromDate.Value,
                                                                                           toDate.Value
                                                                                           ));
                }

                var items = await query.ToListAsync();

                var days = new string[] { "شنبه", "یکشنبه", "دوشنبه", "سه شنبه", "چهارشنبه", "پنج شنبه", "جمعه" };

                var answer = items.GroupBy(g => g.Date)
                             .Select(gg => new vmGetTimeSheetResualt
                {
                    date           = gg.Key.Value,
                    isOpen         = gg.FirstOrDefault().IsOpen,
                    mustHaveHozoor = gg.First().UserMustHasHozoor,
                    dayTimeString  = gg.FirstOrDefault().DayTimeString,
                    date_persian   = gg.First().PersianDate,
                    day_persian    = days[gg.First().DayOfWeek.Value],
                    hozoor         = gg.First().Hozoor,
                    projects       = gg.Where(p => p.Type == "Work" && p.ProjectId.HasValue)
                                     .GroupBy(p => p.ProjectId).Select(pp => new vmGetTimeSheetResualt_Project
                    {
                        id       = pp.Key,
                        title    = pp.First().ProjectTitle,
                        workouts = pp.Where(w => w.TaskId.HasValue)
                                   .GroupBy(w => new { w.TaskId, w.State }).Select(ww => new vmGetTimeSheetResualt_Workout
                        {
                            id      = ww.Key.TaskId,
                            state   = ww.Key.State,
                            title   = ww.First().Title,
                            minutes = ww.First().Minutes
                        }).ToList()
                    }).ToList(),

                    others = gg.Where(p => p.Type == "Other" && p.ProjectId.HasValue)
                             .GroupBy(p => p.State).Select(pp => new vmGetTimeSheetResualt_Project
                    {
                        id       = pp.First().ProjectId,
                        title    = pp.Key,
                        workouts = pp.Where(w => w.TaskId.HasValue)
                                   .GroupBy(w => w.TaskId).Select(ww => new vmGetTimeSheetResualt_Workout
                        {
                            id      = ww.First().TaskId,
                            state   = ww.First().State,
                            title   = ww.First().Title,
                            minutes = ww.Sum(www => www.Minutes)
                        }).ToList()
                    }).ToList()
                }).ToList();

                if (mustCheckDefaultTimeSheetPolocy && !answer.First(a => a.date.Value.Date == now.Date).isOpen.HasValue)
                {
                    //default policy must check maybe is deactivated
                    //if isnot created, must create and today is open beacuase friday is checked in query
                    //اگر زمانش گذشته باید تمدید بشه که با تاریخ های امروز یکسان بشه
                    var userDefaultPolicy = this.DBContext.TimesheetPolicies.FirstOrDefault(p => p.IsDefault && p.UserId == currentUser.ID);
                    if (userDefaultPolicy == null)
                    {
                        userDefaultPolicy = new TimesheetPolicy()
                        {
                            Id                = Guid.NewGuid(),
                            IsDefault         = true,
                            isDeactivated     = false,
                            IsOpen            = true,
                            UserMustHasHozoor = true,
                            UserId            = currentUser.ID,
                        };
                        this.DBContext.TimesheetPolicies.Add(userDefaultPolicy);
                    }

                    userDefaultPolicy.Start      = DateUtility.GetCompanyStartDate();
                    userDefaultPolicy.Finish     = DateUtility.GetCompanyEndDate();
                    userDefaultPolicy.Validity   = DateUtility.GetCompanyEndDate();
                    userDefaultPolicy.CreateDate = DateTime.Now;



                    this.DBContext.SaveChanges();

                    if (numberOfReset < 1)
                    {
                        goto labelForReset;
                    }
                }

                return(Ok(answer));
            }
            catch (Exception ex)
            {
                return(this.ReturnError(ex, "خطا در دریافت اطلاعات تایم شیت"));
            }
        }
Beispiel #21
0
        public async Task <IActionResult> GetTimeSheet(string ver, Guid?userId, DateTime?fromDate, DateTime?toDate)
        {
            var isWantingApprove = userId.HasValue;

            try
            {
                if (!this.MainChecks(ver, out string error))
                {
                    throw new Exception(error);
                }

                DisplayPeriodManager displayPeriodMnager = new DisplayPeriodManager(this._uow);
                User currentUser = new UserHelper().GetCurrent(this._uow, this.UserName);

                if (!fromDate.HasValue)
                {
                    DisplayPeriod displayPeriod = displayPeriodMnager.GetDisplayPeriod(currentUser);


                    if (!fromDate.HasValue)
                    {
                        fromDate = DateTime.Now.AddDays(-7);
                    }
                    if (!toDate.HasValue)
                    {
                        toDate = DateTime.Now;
                    }

                    if (displayPeriod.IsWeekly)
                    {
                        fromDate = DateTime.Today.StartOfWeek(DayOfWeek.Saturday);
                        toDate   = DateTime.Today.EndOfWeek(DayOfWeek.Friday);
                    }
                    else
                    {
                        toDate = fromDate.Value.AddDays(displayPeriod.NumOfDays);
                    }
                }

                var mustCheckDefaultTimeSheetPolocy = false;
                var now = DateTime.Now;
                mustCheckDefaultTimeSheetPolocy = now.Date >= fromDate.Value.Date && now.Date <= toDate.Value.Date; //سعی شده پالیسی فقط دفعه اول چک شود و وقتی عقب جلو می رویم چک نشود چون همان است

                var numberOfReset = -1;

labelForReset:

                numberOfReset++;

                IQueryable <Persistance.QueryEntities.EmployeeTimeSheetFromDB> query = null;

                if (isWantingApprove)
                {
                    query = this.DBContext.spFoundConfirmTimeSheet.FromSqlInterpolated(this.DBContext.spFoundConfirmTimeSheet_str(
                                                                                           currentUser.ID,
                                                                                           userId,
                                                                                           fromDate.Value,
                                                                                           toDate.Value
                                                                                           ));
                }
                else
                {
                    query = this.DBContext.spFoundConfirmTimeSheet.FromSqlInterpolated(this.DBContext.spFoundEmployeeTimeSheet_str(
                                                                                           currentUser.ID,
                                                                                           fromDate.Value,
                                                                                           toDate.Value
                                                                                           ));
                }

                var items = await query.ToListAsync();

                var days = new string[] { "شنبه", "یکشنبه", "دوشنبه", "سه شنبه", "چهارشنبه", "پنج شنبه", "جمعه" };

                var answer = items.GroupBy(g => g.Date)
                             .Select(gg => new vmGetTimeSheetResualt
                {
                    date           = gg.Key.Value,
                    isOpen         = gg.FirstOrDefault().IsOpen,
                    mustHaveHozoor = gg.First().UserMustHasHozoor,
                    dayTimeString  = gg.FirstOrDefault().DayTimeString,
                    date_persian   = gg.First().PersianDate,
                    day_persian    = days[gg.First().DayOfWeek.Value],
                    hozoor         = gg.First().Hozoor,
                    projects       = gg.Where(p => p.Type == "Work" && p.ProjectId.HasValue)
                                     .GroupBy(p => p.ProjectId).Select(pp => new vmGetTimeSheetResualt_Project
                    {
                        id       = pp.Key,
                        title    = pp.First().ProjectTitle,
                        workouts = pp.Where(w => w.TaskId.HasValue)
                                   .GroupBy(w => new { w.TaskId, w.State }).Select(ww => new vmGetTimeSheetResualt_Workout
                        {
                            id      = ww.Key.TaskId,
                            state   = ww.Key.State,
                            title   = ww.First().Title,
                            minutes = ww.First().Minutes
                        }).ToList()
                    }).ToList(),

                    others = gg.Where(p => p.Type == "Other" && p.ProjectId.HasValue)
                             .GroupBy(p => p.State).Select(pp => new vmGetTimeSheetResualt_Project
                    {
                        id       = pp.First().ProjectId,
                        title    = pp.Key,
                        workouts = pp.Where(w => w.TaskId.HasValue)
                                   .GroupBy(w => w.TaskId).Select(ww => new vmGetTimeSheetResualt_Workout
                        {
                            id      = ww.First().TaskId,
                            state   = ww.First().State,
                            title   = ww.First().Title,
                            minutes = ww.Sum(www => www.Minutes)
                        }).ToList()
                    }).ToList()
                }).ToList();

                if (mustCheckDefaultTimeSheetPolocy && !answer.First(a => a.date.Value.Date == now.Date).isOpen.HasValue)
                {
                    createPolicyForUser(currentUser.ID);
                    if (numberOfReset < 1)
                    {
                        goto labelForReset;
                    }
                }

                return(Ok(answer));
            }
            catch (Exception ex)
            {
                return(this.ReturnError(ex, "خطا در دریافت اطلاعات تایم شیت"));
            }
        }
        /// <summary>
        /// بروزرسانی دوره نمایش
        /// </summary>
        /// <param name="DisplayPeriod">موجودیت دوره نمایش</param>
        public void Edit(DisplayPeriod DisplayPeriod)
        {
            var entity = _RASContext.DisplayPeriods.Find(DisplayPeriod.ID);

            FillEntity(entity, DisplayPeriod);
        }
        public IEnumerable <TimeSheetJson> GetNextPeriodConfirm(TimeSheetValueJson workHourJson)
        {
            List <TimeSheetJson> result = new List <TimeSheetJson>();

            if (workHourJson == null)
            {
                workHourJson      = new TimeSheetValueJson();
                workHourJson.Date = DateTime.Now.AddDays(-7);
            }

            UnitOfWork           uow                 = new UnitOfWork();
            UserManager          userManager         = new UserManager(uow);
            TimeSheetManager     timeSheetManager    = new TimeSheetManager(uow);
            DisplayPeriodManager displayPeriodMnager = new DisplayPeriodManager(uow);
            //SyncWithPWA(uow);
            User          currUser      = new UserHelper().GetCurrent();
            User          user          = userManager.GetByID(Guid.Parse(workHourJson.UserId));
            DisplayPeriod displayPeriod = displayPeriodMnager.GetDisplayPeriod(currUser);
            DateTime      toDate        = workHourJson.Date.AddDays(1);

            DateTime fromDate;
            var      type = workHourJson.Value.GetType();

            if (displayPeriod != null)
            {
                fromDate = displayPeriod.StartDate;
                if (displayPeriod.IsWeekly)
                {
                    var Condition = workHourJson.Value.Equals(true) || workHourJson.Date.AddDays(7) < DateTime.Now;
                    if (DateTime.Now > workHourJson.Date && Condition)
                    {
                        fromDate = toDate.StartOfWeek(DayOfWeek.Saturday);
                        toDate   = toDate.EndOfWeek(DayOfWeek.Friday);
                        IEnumerable <PresenceHour> presHours = timeSheetManager.GetPresHoursByUser(currUser, fromDate, toDate);
                        IEnumerable <WorkHour>     workHours = timeSheetManager.GetWorkHoursByUser(currUser, fromDate, toDate);

                        result = TimeSheetAssembler.ToJsonsForConfirm(presHours, workHours, user);
                    }
                    else
                    {
                        fromDate = DateTime.Now.StartOfWeek(DayOfWeek.Saturday);
                        toDate   = DateTime.Now.EndOfWeek(DayOfWeek.Friday);
                        IEnumerable <PresenceHour> presHours = timeSheetManager.GetPresHoursByUser(currUser, fromDate, toDate);
                        IEnumerable <WorkHour>     workHours = timeSheetManager.GetWorkHoursByUser(currUser, fromDate, toDate);
                        result = TimeSheetAssembler.ToJsonsForConfirm(presHours, workHours, user);
                    }
                }
                else
                {
                    toDate = fromDate.AddDays(displayPeriod.NumOfDays);
                    IEnumerable <PresenceHour> presHours = timeSheetManager.GetPresHoursByUser(currUser, fromDate, toDate);
                    if (presHours.Count() < displayPeriod.NumOfDays)
                    {
                        fromDate  = DateTime.Now;
                        toDate    = fromDate.AddDays(displayPeriod.NumOfDays);
                        presHours = timeSheetManager.GetPresHoursByUser(currUser, fromDate, toDate);
                    }
                    IEnumerable <WorkHour> workHours = timeSheetManager.GetWorkHoursByUser(currUser, fromDate, toDate);
                    result = TimeSheetAssembler.ToJsonsForConfirm(presHours, workHours, user);
                }
            }
            else
            {
                fromDate = DateTime.Now.StartOfWeek(DayOfWeek.Saturday);
                toDate   = DateTime.Now.EndOfWeek(DayOfWeek.Friday);
                IEnumerable <PresenceHour> presHours = timeSheetManager.GetPresHoursByUser(currUser, fromDate, toDate);
                IEnumerable <WorkHour>     workHours = timeSheetManager.GetWorkHoursByUser(currUser, fromDate, toDate);
                result = TimeSheetAssembler.ToJsonsForConfirm(presHours, workHours, user);
            }



            return(result);
        }