protected override void DataPortal_Insert()
        {
            using (var dalManager = DataFactoryManager.GetManager())
            {
                var dalFactory = dalManager.GetProvider <IWeekDataFactory>();

                var data = new WeekData();

                using (this.BypassPropertyChecks)
                {
                    this.ModifiedBy   = ((IBusinessIdentity)Csla.ApplicationContext.User.Identity).UserId;
                    this.ModifiedDate = DateTime.Now;
                    this.CreatedBy    = this.ModifiedBy;
                    this.CreatedDate  = this.ModifiedDate;

                    this.Insert(data);

                    data = dalFactory.Insert(data);

                    this.WeekId = data.WeekId;
                }

                // this.FieldManager.UpdateChildren(data);
            }
        }
        internal static Week FetchWeek(WeekData data)
        {
            var result = new Week();

            result.Fetch(data);
            result.MarkOld();

            return(result);
        }
        public WeekData Update(WeekData data)
        {
            var week = MockDb.Weeks
                       .Where(row => row.WeekId == data.WeekId)
                       .Single();

            Csla.Data.DataMapper.Map(data, week);

            return(data);
        }
        public WeekData Update(WeekData data)
        {
            var week = MockDb.Weeks
                .Where(row => row.WeekId == data.WeekId)
                .Single();

            Csla.Data.DataMapper.Map(data, week);

            return data;
        }
        private void Fetch(Week week, WeekData weekData)
        {
            DataMapper.Map(week, weekData);

            weekData.CreatedByUser = new UserData();
            DataMapper.Map(week.CreatedByUser, weekData.CreatedByUser);

            weekData.ModifiedByUser = new UserData();
            DataMapper.Map(week.ModifiedByUser, weekData.ModifiedByUser);
        }
        public WeekData Fetch(WeekData data)
        {
            data.CreatedByUser = MockDb.Users
                .Where(row => row.UserId == data.CreatedBy)
                .Single();

            data.ModifiedByUser = MockDb.Users
                .Where(row => row.UserId == data.ModifiedBy)
                .Single();

            return data;
        }
 protected void Update(WeekData data)
 {
     data.WeekId       = this.WeekId;
     data.EndDate      = this.EndDate;
     data.Period       = this.Period;
     data.StartDate    = this.StartDate;
     data.Year         = this.Year;
     data.CreatedBy    = this.CreatedBy;
     data.CreatedDate  = this.CreatedDate;
     data.ModifiedBy   = this.ModifiedBy;
     data.ModifiedDate = this.ModifiedDate;
 }
        public WeekData Fetch(WeekData data)
        {
            data.CreatedByUser = MockDb.Users
                                 .Where(row => row.UserId == data.CreatedBy)
                                 .Single();

            data.ModifiedByUser = MockDb.Users
                                  .Where(row => row.UserId == data.ModifiedBy)
                                  .Single();

            return(data);
        }
 private void Child_Fetch(WeekData data)
 {
     this.WeekId         = data.WeekId;
     this.EndDate        = data.EndDate;
     this.Period         = data.Period;
     this.StartDate      = data.StartDate;
     this.Year           = data.Year;
     this.CreatedBy      = data.CreatedBy;
     this.CreatedByName  = data.CreatedByUser.Name;
     this.CreatedDate    = data.CreatedDate;
     this.ModifiedBy     = data.ModifiedBy;
     this.ModifiedByName = data.ModifiedByUser.Name;
     this.ModifiedDate   = data.ModifiedDate;
 }
        public WeekData Fetch(WeekDataCriteria criteria)
        {
            using (var ctx = Csla.Data.ObjectContextManager<ApplicationEntities>
                         .GetManager(Database.ApplicationConnection, false))
            {
                var week = this.Fetch(ctx, criteria)
                    .Single();

                var weekData = new WeekData();

                this.Fetch(week, weekData);

                return weekData;
            }
        }
        private void AddRowHeader(Table table, WeekData week, int weekCount)
        {
            var sb = new StringBuilder();

            sb.AppendLine($"SW: {weekCount}");
            sb.Append(($"{this.datePattern.Format(week.WeekStart)} - {this.datePattern.Format(week.WeekEnd)}"));
            var par = new Paragraph(sb.ToString());

            par.SetVerticalAlignment(VerticalAlignment.MIDDLE);
            var cell = new Cell();

            cell.Add(par);
            cell.SetVerticalAlignment(VerticalAlignment.MIDDLE);
            table.AddCell(cell);
        }
        public WeekData Fetch(WeekDataCriteria criteria)
        {
            using (var ctx = Csla.Data.ObjectContextManager <ApplicationEntities>
                             .GetManager(Database.ApplicationConnection, false))
            {
                var week = this.Fetch(ctx, criteria)
                           .Single();

                var weekData = new WeekData();

                this.Fetch(week, weekData);

                return(weekData);
            }
        }
        public WeekData Insert(WeekData data)
        {
            if (MockDb.Weeks.Count() == 0)
            {
                data.WeekId = 1;
            }
            else
            {
                data.WeekId = MockDb.Weeks.Select(row => row.WeekId).Max() + 1;
            }

            MockDb.Weeks.Add(data);

            return data;
        }
        public WeekData Insert(WeekData data)
        {
            if (MockDb.Weeks.Count() == 0)
            {
                data.WeekId = 1;
            }
            else
            {
                data.WeekId = MockDb.Weeks.Select(row => row.WeekId).Max() + 1;
            }

            MockDb.Weeks.Add(data);

            return(data);
        }
        private static WeekData GetWeekData()
        {
            if (options != null && !options.IncludeWeekData)
            {
                return(null);
            }

            XElement weekDataElement = (from i in supplementalDataDocument.Elements("supplementalData").Elements("weekData")
                                        select i).FirstOrDefault();

            if (weekDataElement == null)
            {
                return(null);
            }

            Progress("Adding week data", String.Empty);

            WeekData weekData = new WeekData();

            List <XElement> minDaysCountElements = weekDataElement.Elements("minDays").ToList();

            if (minDaysCountElements.Count > 0)
            {
                List <MinDaysCount> minDaysCounts = new List <MinDaysCount>();
                foreach (XElement minDaysCountElement in minDaysCountElements)
                {
                    MinDaysCount minDaysCount = new MinDaysCount();
                    minDaysCount.Count     = int.Parse(minDaysCountElement.Attribute("count").Value.ToString());
                    minDaysCount.RegionIds = minDaysCountElement.Attribute("territories").Value.ToString().Split(' ');
                    minDaysCounts.Add(minDaysCount);
                }

                weekData.MinDaysCounts = minDaysCounts.ToArray();
            }

            weekData.FirstDayOfWeeks = GetRegionDayOfWeeks(weekDataElement, "firstDay");

            weekData.WeekendStarts = GetRegionDayOfWeeks(weekDataElement, "weekendStart");

            weekData.WeekendEnds = GetRegionDayOfWeeks(weekDataElement, "weekendEnd");

            Progress("Added week data", string.Empty, ProgressEventType.Added, weekData);

            return(weekData);
        }
        public WeekData Insert(WeekData data)
        {
            using (var ctx = Csla.Data.ObjectContextManager <ApplicationEntities>
                             .GetManager(Database.ApplicationConnection, false))
            {
                var week = new Week();

                DataMapper.Map(data, week);

                ctx.ObjectContext.AddToWeeks(week);

                ctx.ObjectContext.SaveChanges();

                data.WeekId = week.WeekId;

                return(data);
            }
        }
        public WeekData Update(WeekData data)
        {
            using (var ctx = Csla.Data.ObjectContextManager <ApplicationEntities>
                             .GetManager(Database.ApplicationConnection, false))
            {
                var week =
                    new Week
                {
                    WeekId = data.WeekId
                };

                ctx.ObjectContext.Weeks.Attach(week);

                DataMapper.Map(data, week);

                ctx.ObjectContext.SaveChanges();

                return(data);
            }
        }
        public WeekData[] FetchLookupInfoList(WeekDataCriteria criteria)
        {
            using (var ctx = Csla.Data.ObjectContextManager<ApplicationEntities>
                          .GetManager(Database.ApplicationConnection, false))
            {
                var weeks = this.Fetch(ctx, criteria)
                    .AsEnumerable();

                var weekDataList = new List<WeekData>();

                foreach (var week in weeks)
                {
                    var weekData = new WeekData();

                    this.Fetch(week, weekData);

                    weekDataList.Add(weekData);
                }

                return weekDataList.ToArray();
            }
        }
        public WeekData[] FetchLookupInfoList(WeekDataCriteria criteria)
        {
            using (var ctx = Csla.Data.ObjectContextManager <ApplicationEntities>
                             .GetManager(Database.ApplicationConnection, false))
            {
                var weeks = this.Fetch(ctx, criteria)
                            .AsEnumerable();

                var weekDataList = new List <WeekData>();

                foreach (var week in weeks)
                {
                    var weekData = new WeekData();

                    this.Fetch(week, weekData);

                    weekDataList.Add(weekData);
                }

                return(weekDataList.ToArray());
            }
        }
 protected void Insert(WeekData data)
 {
     this.Update(data);
 }
        public WeekData Update(WeekData data)
        {
            using (var ctx = Csla.Data.ObjectContextManager<ApplicationEntities>
                         .GetManager(Database.ApplicationConnection, false))
            {
                var week =
                    new Week
                    {
                        WeekId = data.WeekId
                    };

                ctx.ObjectContext.Weeks.Attach(week);

                DataMapper.Map(data, week);

                ctx.ObjectContext.SaveChanges();

                return data;
            }
        }
        private void Fetch(Week week, WeekData weekData)
        {
            DataMapper.Map(week, weekData);

            weekData.CreatedByUser = new UserData();
            DataMapper.Map(week.CreatedByUser, weekData.CreatedByUser);

            weekData.ModifiedByUser = new UserData();
            DataMapper.Map(week.ModifiedByUser, weekData.ModifiedByUser);
        }
        private void UpdateRenderData()
        {
            renderData            = new RenderData();
            renderData.DaysOfWeek = new List <string>(7);

            string[]  dayNames       = Culture.DateTimeFormat.AbbreviatedDayNames;
            DayOfWeek firstDayOfWeek = this.FirstDayOfWeek;

            DateTime minDateEffective = MinDateEffective;
            DateTime maxDateEffective = MaxDateEffective;
            int      minYear          = minDateEffective.Year;
            int      maxYear          = maxDateEffective.Year;

            renderData.Years = Enumerable.Range(minYear, maxYear - minYear + 1).Reverse().ToList();

            for (int i = 0; i < 7; i++)
            {
                renderData.DaysOfWeek.Add(dayNames[((int)firstDayOfWeek + i) % 7]);
            }

            renderData.Months = Culture.DateTimeFormat.MonthNames.Take(12)             // returns 13 items, see https://docs.microsoft.com/en-us/dotnet/api/system.globalization.datetimeformatinfo.monthnames?view=net-5.0
                                .Select((name, index) => new MonthData
            {
                Index   = index,
                Name    = name,
                Enabled = (new DateTime(DisplayMonth.Year, index + 1, DateTime.DaysInMonth(DisplayMonth.Year, index + 1)) >= minDateEffective) && (new DateTime(DisplayMonth.Year, index + 1, 1) <= maxDateEffective)
            })
                                .ToList();

            renderData.Weeks = new List <WeekData>(6);

            DateTime currentDay = FirstDayToDisplay;
            DateTime valueDay   = Value?.Date ?? default;
            DateTime today      = DateTime.Today;

            for (var week = 0; week < 6; week++)
            {
                WeekData weekData = new WeekData();
                weekData.Days = new List <DayData>(7);

                for (int day = 0; day < 7; day++)
                {
                    CalendarDateCustomizationResult customization = GetDateCustomization(DateCustomizationProviderEffective, currentDay);

                    bool clickEnabled = (currentDay >= minDateEffective) &&                  // can click only days starting MinDate
                                        (currentDay <= maxDateEffective) && (customization?.Enabled ?? true);                    // can click only days ending MaxDate
                    string cssClass = CssClassHelper.Combine(
                        clickEnabled ? "active" : "disabled",
                        (currentDay == valueDay) ? "selected" : null,                          // currently selected day has "selected" class
                        ((currentDay.Month == DisplayMonth.Month) && (currentDay.Year == DisplayMonth.Year)) ? "in" : "out",
                        (currentDay == today) ? "hx-calendar-today" : null,
                        ((currentDay.DayOfWeek == DayOfWeek.Saturday) || (currentDay.DayOfWeek == DayOfWeek.Sunday)) ? "weekend" : null,
                        customization?.CssClass
                        );

                    DayData dayData = new DayData
                    {
                        Date         = currentDay,
                        DayInMonth   = currentDay.Day.ToString("d", Culture.DateTimeFormat),
                        CssClass     = cssClass,
                        ClickEnabled = clickEnabled
                    };
                    weekData.Days.Add(dayData);
                    currentDay = currentDay.AddDays(1);
                }
                renderData.Weeks.Add(weekData);
            }

            renderData.PreviousMonthEnabled = minDateEffective < DisplayMonth;             // DisplayMonth is always the first fay of month
            renderData.NextMonthEnabled     = maxDateEffective > new DateTime(DisplayMonth.Year, DisplayMonth.Month, DateTime.DaysInMonth(DisplayMonth.Year, DisplayMonth.Month));
        }
        public WeekData Insert(WeekData data)
        {
            using (var ctx = Csla.Data.ObjectContextManager<ApplicationEntities>
                           .GetManager(Database.ApplicationConnection, false))
            {
                var week = new Week();

                DataMapper.Map(data, week);

                ctx.ObjectContext.AddToWeeks(week);

                ctx.ObjectContext.SaveChanges();

                data.WeekId = week.WeekId;

                return data;
            }
        }