Esempio 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;
        }
 public ActionResult Edit(DailyBreadModel dailyBreadModel)
 {
     var dto = new DailyBreadItemDto();
     dto.InjectFrom(dailyBreadModel);
     var result = _adminDailyBreadService.SaveDailyBreadItem(CurrentProfile.ClientId, dto);
     if (result.IsValid)
     {
         return RedirectToAction("Index");
     }
     ModelState.AddModelError(string.Empty, result.ValidationSummaryToString());
     SetEditViewBag();
     return View(dailyBreadModel);
 }
Esempio 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;
        }