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(); }