Exemplo n.º 1
0
        public IActionResult GetDefualtConfigData()
        {
            try
            {
                var conf = this.DBContext.TimeSheetConfig.FirstOrDefault();
                if (conf == null)
                {
                    conf = new TimeSheetConfig()
                    {
                        DefualtOpenTimeSheetWeeks = 1,
                        TimeSheetLockDate         = DateTime.Today
                    };
                    this.DBContext.TimeSheetConfig.Add(conf);
                }

                return(Ok(new vmTimeSheetConfig()
                {
                    defualtOpenTimeSheetWeeks = conf.DefualtOpenTimeSheetWeeks,
                    timeSheetLockDate = DateUtility.GetPersianDate(conf.TimeSheetLockDate)
                }));
            }
            catch (Exception ex)
            {
                return(this.ReturnError(ex, "خطا در دریافت اطلاعات پیش فرض سیستم"));
            }
        }
Exemplo n.º 2
0
        public IActionResult SaveDefualtConfigData(vmTimeSheetConfig request)
        {
            try
            {
                if (request == null)
                {
                    throw new Exception("اطلاعات ارسال نشده است");
                }
                if (!request.defualtOpenTimeSheetWeeks.HasValue)
                {
                    throw new Exception("تعداد هفته پیش فرض نمی تواند خالی باشد");
                }
                if (string.IsNullOrEmpty(request.timeSheetLockDate))
                {
                    throw new Exception("تاریخ پیش فرض نمی تواند خالی باشد");
                }

                var conf = this.DBContext.TimeSheetConfig.FirstOrDefault();
                if (conf == null)
                {
                    conf = new TimeSheetConfig()
                    {
                        DefualtOpenTimeSheetWeeks = 1,
                        TimeSheetLockDate         = DateTime.Today
                    };
                    this.DBContext.TimeSheetConfig.Add(conf);
                }

                if (conf.DefualtOpenTimeSheetWeeks != request.defualtOpenTimeSheetWeeks)
                {
                    changeDefualtOpenTimeSheetWeeks(request.defualtOpenTimeSheetWeeks.Value);
                }

                conf.DefualtOpenTimeSheetWeeks = request.defualtOpenTimeSheetWeeks.Value;
                conf.TimeSheetLockDate         = DateUtility.GetMiladiDate((request.timeSheetLockDate));
                this.DBContext.SaveChanges();

                return(Ok(true));
            }
            catch (Exception ex)
            {
                return(this.ReturnError(ex, "خطا در ثبت اطلاعات پیش فرض سیستم"));
            }
        }
Exemplo n.º 3
0
        private void createPolicyForUser(Guid currentUserId)
        {
            //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 == currentUserId);
            var timeSheetConfig   = this.DBContext.TimeSheetConfig.FirstOrDefault();

            if (timeSheetConfig == null)
            {
                timeSheetConfig = new TimeSheetConfig()
                {
                    DefualtOpenTimeSheetWeeks = 1,
                    TimeSheetLockDate         = DateTime.Today
                };
                this.DBContext.TimeSheetConfig.Add(timeSheetConfig);
            }

            if (userDefaultPolicy == null)
            {
                userDefaultPolicy = new TimesheetPolicy()
                {
                    Id                = Guid.NewGuid(),
                    IsDefault         = true,
                    isDeactivated     = false,
                    IsOpen            = true,
                    UserMustHasHozoor = true,
                    UserId            = currentUserId,
                };
                this.DBContext.TimesheetPolicies.Add(userDefaultPolicy);
            }

            userDefaultPolicy.Start      = DateUtility.GetWeekStartDate(timeSheetConfig.DefualtOpenTimeSheetWeeks);
            userDefaultPolicy.Finish     = DateUtility.GetWeekEndtDate();
            userDefaultPolicy.Validity   = DateUtility.GetWeekEndtDate();
            userDefaultPolicy.CreateDate = DateTime.Now;


            this.DBContext.SaveChanges();
        }