public bool SetItemSections(ECollateralDetails sectionInfo, int userId, out bool bNeedVerify)
        {
            bNeedVerify = false;

            var dbItem = database.eCollateralItems.FirstOrDefault(i => i.ItemID == sectionInfo.ItemID);

            if (dbItem != null)
            {
                dbItem.LastModifiedByDateTime = DateTime.UtcNow;
                dbItem.LastModifiedByUserID   = userId;

                dbItem.IncludeDealerImage = sectionInfo.AddDealerImage && dbItem.DealershipID.HasValue && !string.IsNullOrEmpty(dbItem.Company.ImageFileName);

                for (int i = 0; i < Layouts.LayoutSections[dbItem.LayoutID.Value]; i++)
                {
                    var uiSection = sectionInfo.Details[i];
                    var dbSection = dbItem.eCollateralSections.FirstOrDefault(s => s.Sequence == i);
                    if (dbSection == null)
                    {
                        if (uiSection.ImageID != null || (uiSection.Content ?? "").Any())
                        {
                            dbItem.eCollateralSections.Add(new eCollateralSection()
                            {
                                ImageID  = uiSection.ImageID,
                                Content  = uiSection.Content,
                                Sequence = i
                            });
                        }
                    }
                    else if (uiSection.ImageID != null || (uiSection.Content ?? "").Any())
                    {
                        dbSection.ImageID = uiSection.ImageID;
                        dbSection.Content = uiSection.Content;
                    }
                    else
                    {
                        database.eCollateralSections.Remove(dbSection);
                    }
                }

                bNeedVerify = ((dbItem.Status == StatusTypes.Incomplete) || (dbItem.Status == StatusTypes.Unapproved));
                if (dbItem.Status == StatusTypes.Approved && !dbItem.IsTemplate)
                {
                    dbItem.Status = StatusTypes.New;
                }

                return(database.SaveChanges() > 0);
            }

            throw new Exception("Unable to find eCollateral");
        }
Ejemplo n.º 2
0
        public ActionResult EditLayout(ECollateralDetails dInfo)
        {
            if (ModelState.IsValid)
            {
                using (var eRepository = new ECollateralRepository())
                {
                    bool bNeedVerify;
                    eRepository.SetItemSections(dInfo, PaoliWebUser.CurrentUser.UserId, out bNeedVerify);

                    return(RedirectToAction(bNeedVerify ? "VerifyLayout" : "ViewLayout", new { id = dInfo.ItemID }));
                }
            }

            return(View(dInfo));
        }
        private ECollateralDetails ToECollateralDetails(eCollateralItem dbItem)
        {
            var dInfo = new ECollateralDetails();

            dInfo.ItemID          = dbItem.ItemID;
            dInfo.Name            = dbItem.FileName;
            dInfo.LayoutName      = Layouts.LayoutTitles[dbItem.LayoutID.Value];
            dInfo.EditViewName    = Layouts.LayoutEditViews[dbItem.LayoutID.Value];
            dInfo.DisplayViewName = Layouts.LayoutDisplayViews[dbItem.LayoutID.Value];
            dInfo.Details         = new List <ECollateralDetails.DetailItem>();
            if (dbItem.DealershipID.HasValue)
            {
                dInfo.AddDealerImage  = dbItem.IncludeDealerImage && !string.IsNullOrEmpty(dbItem.Company.ImageFileName);
                dInfo.DealerImageName = dbItem.Company.ImageFileName;
            }
            else
            {
                dInfo.AddDealerImage  = false;
                dInfo.DealerImageName = null;
            }

            for (int i = 0; i < Layouts.LayoutSections[dbItem.LayoutID.Value]; i++)
            {
                dInfo.Details.Add(new ECollateralDetails.DetailItem());
            }

            foreach (var dbDetail in dbItem.eCollateralSections)
            {
                dInfo.Details[dbDetail.Sequence] = new ECollateralDetails.DetailItem()
                {
                    ImageID       = dbDetail.ImageID,
                    Content       = System.Web.HttpUtility.HtmlDecode(dbDetail.Content),
                    ImageFileName = dbDetail.ImageID.HasValue ? dbDetail.ImageFile.ThumbnailImageData("l16to9").FileName : null
                };
            }

            return(dInfo);
        }