Beispiel #1
0
        public ActionResult SetLayout(ECollateralLayout layoutInfo)
        {
            if (ModelState.IsValid)
            {
                using (var eRepository = new ECollateralRepository())
                {
                    eRepository.SetLayout(layoutInfo, PaoliWebUser.CurrentUser.UserId);

                    return(RedirectToAction("EditLayout", new { id = layoutInfo.ItemID }));
                }
            }

            return(View(layoutInfo));
        }
        public bool SetLayout(ECollateralLayout layoutInfo, int userId)
        {
            var dbUser = database.Users.FirstOrDefault(u => u.UserID == userId);

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

            if (dbItem != null)
            {
                if (dbItem.LayoutID != layoutInfo.LayoutID)
                {
                    dbItem.LayoutID = layoutInfo.LayoutID;
                    foreach (var contentType in LayoutTypes.LayoutList.Keys)
                    {
                        if (LayoutTypes.LayoutList[contentType].Contains(layoutInfo.LayoutID))
                        {
                            dbItem.ContentType = contentType;
                            break;
                        }
                    }
                    dbItem.LastModifiedByUserID   = userId;
                    dbItem.LastModifiedByDateTime = DateTime.UtcNow;

                    foreach (var dbSection in dbItem.eCollateralSections.ToList())
                    {
                        database.eCollateralSections.Remove(dbSection);
                    }

                    var defaultList = Layouts.LayoutDefaultSections[dbItem.LayoutID.Value];
                    for (int i = 0; i < defaultList.Count; i++)
                    {
                        var dbSection = new eCollateralSection();
                        dbSection.Content = string.Format(defaultList[i], dbUser.FullName.DefaultString("Name"), dbUser.Address1.DefaultString("Address"),
                                                          dbUser.City.DefaultString("City"), dbUser.State.DefaultString("ST"), dbUser.Zip.DefaultString("ZIP"), dbUser.BusinessPhone.DefaultString("(317) 555-1234"),
                                                          dbUser.Email);
                        dbSection.Sequence = i;

                        dbItem.eCollateralSections.Add(dbSection);
                    }
                }

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

            throw new Exception("Unable to find eCollateral");
        }