private DateSettingsDialog(DateSettings dateSettings)
        {
            InitializeComponent();


            _dateSettings = dateSettings;

            dtpStartDate.MinDate = DateTime.MinValue;
            dtpStartDate.MaxDate = DateTime.MaxValue;
            dtpEndDate.MinDate   = DateTime.MinValue;
            dtpEndDate.MaxDate   = DateTime.MaxValue;

            dtpStartDate.DataBindings.Add(new Binding("Value", _dateSettings, "StartDate")
            {
                DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged
            });
            dtpEndDate.DataBindings.Add(new Binding("Value", _dateSettings, "EndDate")
            {
                DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged
            });

            // Quick radio Buttons
            rbLastDay.Tag   = RoundMode.LastDay;
            rbLastWeek.Tag  = RoundMode.LastWeek;
            rbLastMonth.Tag = RoundMode.LastMonth;
            rbLastYear.Tag  = RoundMode.LastYear;
            foreach (var rb in new[] { rbLastDay, rbLastWeek, rbLastMonth, rbLastYear })
            {
                rb.CheckedChanged += rbQuickMode_CheckedChanged;
            }
        }
        public static DialogResult ShowDialog(DateSettings dateSettings)
        {
            if (dateSettings == null)
            {
                throw new ArgumentNullException("dateSettings");
            }

            using (var form = new DateSettingsDialog(dateSettings.Copy()))
            {
                if (form.ShowDialog() == DialogResult.OK)
                {
                    dateSettings.Copy(form._dateSettings);
                }

                return(form.DialogResult);
            }
        }
Exemplo n.º 3
0
        public async Task <Fund> CreateFund(Fund fund)
        {
            using (PortfolioAceDbContext context = _contextFactory.CreateDbContext())
            {
                EntityEntry <Fund> res = await context.Funds.AddAsync(fund);

                await context.SaveChangesAsync();

                // Once the fund has been created, I then create the accounting periods

                // set the monthly or daily account periods for up to one year ahead...
                DateTime        startDate = fund.LaunchDate;
                List <DateTime> allPeriods;
                if (fund.NAVFrequency == "Daily")
                {
                    // get daily dates from fund launch to a year ahead
                    allPeriods = DateSettings.AnnualWorkingDays(startDate);
                }
                else
                {
                    // get month end dates from fund launch to a year ahead
                    allPeriods = DateSettings.AnnualMonthEnds(startDate);
                }
                // add all the dates to the new periods
                List <AccountingPeriodsDIM> initialPeriods = new List <AccountingPeriodsDIM>();
                foreach (DateTime period in allPeriods)
                {
                    AccountingPeriodsDIM newPeriod;
                    newPeriod = new AccountingPeriodsDIM {
                        AccountingDate = period.Date, isLocked = false, FundId = fund.FundId
                    };
                    initialPeriods.Add(newPeriod);
                }
                context.Periods.AddRange(initialPeriods);
                await context.SaveChangesAsync();

                return(res.Entity);
            }
        }
Exemplo n.º 4
0
 public DateAnonymizer(DateSettings dateSettings)
 {
     this.dateSettings = dateSettings;
 }
        public ServiceResult <string> Save(BlogEntryModel entryModel)
        {
            if (entryModel == null)
            {
                throw new ArgumentNullException("entryModel");
            }
            entryModel.RebuildTagsFromString();

            BlogEntry entry = null;

            if (!Exists(entryModel.Slug))
            {
                entry = new BlogEntry
                {
                    Slug        = entryModel.Title.ToUrlSlug(),
                    DateCreated = DateTime.Now
                };

                if (Exists(entry.Slug))
                {
                    return(ServiceResult <string> .Error("Sorry, a post with that slug already exists."));
                }
            }
            else
            {
                entry             = AutoMapper.Mapper.Map <BlogEntryEntity, BlogEntry>(_blogRepository.Single <BlogEntryEntity>(b => b.Slug == entryModel.Slug));
                entry.DateCreated = DateTime.ParseExact(entryModel.Date, DateSettings.DateStringFormat(), Thread.CurrentThread.CurrentCulture);

                var slugChanged =
                    !string.Equals(entryModel.Slug, entryModel.NewSlug, StringComparison.InvariantCultureIgnoreCase) &&
                    !string.IsNullOrWhiteSpace(entryModel.NewSlug);

                if (slugChanged)
                {
                    if (Exists(entryModel.NewSlug))
                    {
                        return(ServiceResult <string> .Error("Sorry, a post with that slug already exists."));
                    }
                    //delete current one as slug is the ID will create / save a new one.
                    Delete(entryModel.Slug);
                    entry.Slug = entryModel.NewSlug.ToLowerInvariant();
                }
            }

            if (!IsValidSlug(entry.Slug))
            {
                return(ServiceResult <string> .Error("That's not a valid slug. Only letters, numbers and hypens are allowed."));
            }

            entry.Title            = entryModel.Title;
            entry.Markdown         = entryModel.Markdown;
            entry.Summary          = CreateSummary(entryModel.Markdown);
            entry.IsPublished      = entryModel.IsPublished;
            entry.IsCodePrettified = entryModel.IsCodePrettified;

            entry.Author = _blogUserService.FindByName(_currentUserService.GetUserName()).DisplayName;

            //update all the tags.
            var tags = _blogRepository.All <TagEntity>().ToArray();

            var distinctTags = entryModel.Tags.Distinct();
            var trimmedTags  = distinctTags.Select(t => t.Trim().ToLowerInvariant()).ToArray();
            var matchedTags  = tags.Where(t => trimmedTags.Contains(t.Name.ToLowerInvariant())).ToArray();

            var newTags = trimmedTags.Where(t => tags.All(tag => tag.Name.ToLowerInvariant() != t))
                          .Select(t => new TagEntity {
                Id = 0, Name = t
            }).ToArray();

            //ensure new tags are added to the list of known tags.
            foreach (var newTag in newTags)
            {
                _blogRepository.Add(newTag);
            }

            var actualTags = newTags.Union(matchedTags);

            var entryEntity = AutoMapper.Mapper.Map <BlogEntry, BlogEntryEntity>(entry);

            entryEntity.Tags.Clear();
            entryEntity.Tags.AddRange(actualTags);

            _blogRepository.Save(entryEntity, b => b.Slug == entry.Slug);

            _blogTagService.RemoveUnsedTags();
            _blogTagService.UpdateTagCount();

            return(ServiceResult <string> .Success(entry.Slug));
        }
Exemplo n.º 6
0
 public DateAnonymizer(DateSettings dateSettings)
 {
     this.dateSettings = dateSettings;
 }
Exemplo n.º 7
0
 public DateAnonymizer(DateSettings settings)
 {
     Settings = settings;
     BaseDate = new System.DateTime(1900, 1, 1);
 }