Ejemplo n.º 1
0
        public DailyBreadItemDto MapFromDomain(DailyBreadItem domain)
        {
            if (domain == null)
            {
                return new DailyBreadItemDto
                {
                    DatePublished = DateTime.UtcNow
                };
            }

            var mapped = new DailyBreadItemDto();
            mapped.InjectFrom(domain);

            mapped.Labels = new List<DailyBreadLabelItemDto>();
            if (domain.Labels != null)
            {
                mapped.Labels = domain.Labels.Select(o =>
                {
                    var li = new DailyBreadLabelItemDto();
                    li.DailyBreadId = o.DailyBreadId;
                    li.Id = o.Id;
                    li.LabelId = o.LabelId;
                    if (o.Label != null)
                    {
                        li.LabelName = o.Label.LabelName;
                        li.LabelDescription = o.Label.LabelDescription;
                        li.IsDeleted = o.Label.IsDeleted;
                        li.ClientId = o.Label.ClientId;
                    }
                    return li;
                }).ToList();
            }

            return mapped;
        }
Ejemplo n.º 2
0
        public ValidationDictionary <ViewModelDailyBreadItem> SaveDailyBreadItem(int clientId, ViewModelDailyBreadItem viewModelDailyBread)
        {
            var validator = new ValidationDictionary <ViewModelDailyBreadItem>();

            if (viewModelDailyBread == null)
            {
                validator.IsValid = false;
                validator.AddError("", "The XX you're trying to save is null");
                return(validator);
            }

            // rule based here


            DailyBreadItem dailyBreadItem;

            if (viewModelDailyBread.DailyBreadId <= 0)
            {
                dailyBreadItem = new DailyBreadItem();
                dailyBreadItem.InjectFrom(viewModelDailyBread);
                dailyBreadItem.DateCreated     = DateTime.UtcNow;
                dailyBreadItem.DateLastUpdated = DateTime.UtcNow;
                dailyBreadItem.ClientId        = clientId;

                _dailyBreadItemRepository.Add(dailyBreadItem);
            }
            else
            {
                dailyBreadItem = _dailyBreadItemRepository.FindBy(o => !o.IsDeleted &&
                                                                  o.DailyBreadId == viewModelDailyBread.DailyBreadId &&
                                                                  o.ClientId == clientId);

                if (dailyBreadItem != null)
                {
                    var createdDate = dailyBreadItem.DateCreated;
                    dailyBreadItem.InjectFrom(viewModelDailyBread);
                    dailyBreadItem.DateLastUpdated = DateTime.UtcNow;
                    dailyBreadItem.DateCreated     = createdDate;
                    dailyBreadItem.IsDeleted       = false;

                    _dailyBreadItemRepository.Update(dailyBreadItem);
                }
            }

            UpdateDailyBreadUrl(dailyBreadItem.DailyBreadId);

            var pinged = GetDailyBreadItem(clientId, dailyBreadItem.DailyBreadId);

            validator.IsValid       = true;
            validator.RelatedObject = pinged;
            return(validator);
        }
Ejemplo n.º 3
0
        public ValidationDictionary<DailyBreadItemDto> SaveDailyBreadItem(int clientId, DailyBreadItemDto dailyBreadDto)
        {
            var validator = new ValidationDictionary<DailyBreadItemDto>();
            if (dailyBreadDto == null)
            {
                validator.IsValid = false;
                validator.AddError("", "The XX you're trying to save is null");
                return validator;
            }

            // rule based here

            DailyBreadItem dailyBreadItem;

            if (dailyBreadDto.DailyBreadId <= 0)
            {
                dailyBreadItem = new DailyBreadItem();
                dailyBreadItem.DailyBreadTitle = dailyBreadDto.DailyBreadTitle;
                dailyBreadItem.DailyBreadUrl = dailyBreadDto.DailyBreadUrl;
                dailyBreadItem.DailyBreadSummary = dailyBreadDto.DailyBreadSummary;
                dailyBreadItem.DatePublished = dailyBreadDto.DatePublished;
                dailyBreadItem.DailyBreadBook = dailyBreadDto.DailyBreadBook;
                dailyBreadItem.DailyBreadBookChapter = dailyBreadDto.DailyBreadBookChapter;
                dailyBreadItem.DailyBreadBookVerse1 = dailyBreadDto.DailyBreadBookVerse1;
                dailyBreadItem.DailyBreadBookVerse2 = dailyBreadDto.DailyBreadBookVerse2;
                dailyBreadItem.DailyBreadBookContent = dailyBreadDto.DailyBreadBookContent;
                dailyBreadItem.DailyBreadContent = dailyBreadDto.DailyBreadContent;
                dailyBreadItem.DateCreated = DateTime.UtcNow;
                dailyBreadItem.DateLastUpdated = DateTime.UtcNow;
                dailyBreadItem.DailyBreadBookLang = dailyBreadDto.DailyBreadBookLang;
                dailyBreadItem.ClientId = clientId;

                _dailyBreadItemRepository.Add(dailyBreadItem);
            }
            else
            {
                dailyBreadItem = _dailyBreadItemRepository.FindBy(o => !o.IsDeleted
                    && o.DailyBreadId == dailyBreadDto.DailyBreadId
                    && o.ClientId == clientId);

                if (dailyBreadItem != null)
                {
                    dailyBreadItem.DailyBreadTitle = dailyBreadDto.DailyBreadTitle;
                    dailyBreadItem.DailyBreadUrl = dailyBreadDto.DailyBreadUrl;
                    dailyBreadItem.DailyBreadSummary = dailyBreadDto.DailyBreadSummary;
                    dailyBreadItem.DatePublished = dailyBreadDto.DatePublished;
                    dailyBreadItem.DailyBreadBook = dailyBreadDto.DailyBreadBook;
                    dailyBreadItem.DailyBreadBookChapter = dailyBreadDto.DailyBreadBookChapter;
                    dailyBreadItem.DailyBreadBookVerse1 = dailyBreadDto.DailyBreadBookVerse1;
                    dailyBreadItem.DailyBreadBookVerse2 = dailyBreadDto.DailyBreadBookVerse2;
                    dailyBreadItem.DailyBreadBookContent = dailyBreadDto.DailyBreadBookContent;
                    dailyBreadItem.DailyBreadContent = dailyBreadDto.DailyBreadContent;
                    dailyBreadItem.DateLastUpdated = DateTime.UtcNow;
                    dailyBreadItem.DailyBreadBookLang = dailyBreadDto.DailyBreadBookLang;
                    dailyBreadItem.IsDeleted = false;

                    _dailyBreadItemRepository.Update(dailyBreadItem);
                }
            }

            dailyBreadItem = dailyBreadItem ?? new DailyBreadItem();
            UpdateDailyBreadUrl(dailyBreadItem.DailyBreadId);

            var pinged = GetDailyBreadItem(clientId, dailyBreadItem.DailyBreadId);
            validator.IsValid = true;
            validator.RelatedObject = pinged;
            return validator;
        }