Exemplo n.º 1
0
        public ActionResult CreateKeyPointContainer(PostCreateKeyPointModel model)
        {
            try
            {
                if (Request.Cookies["MagazineId"].Value == null)
                {
                    SetMessage("Lo sentimos, ha ocurrido un error. Inténtelo de nuevo.", BootstrapAlertTypes.Danger); return(RedirectToAction("Index", "Magazines"));
                }
                int magId = Int32.Parse(Request.Cookies["MagazineId"].Value);

                var length = model.Image.Count();
                var keyPointContainerModel = new KeyPointsContainer
                {
                    Name        = model.KeyPointsContainer.Name,
                    Description = model.KeyPointsContainer.Description,
                    Kguid       = Guid.NewGuid().ToString(),
                    MagazineId  = magId,
                    IsDeleted   = false
                };

                var keyPointContainer = MagazineService.CreateKeyPointContainer(keyPointContainerModel);

                for (var i = 0; i < length; i++)
                {
                    var title          = model.Title != null ? model.Title.Count >= i ? model.Title[i] : "" : "";
                    var description    = model.Description != null ? model.Description.Count >= i ? model.Description[i] : "" : "";
                    var url            = model.Url != null ? model.Url.Count >= i ? model.Url[i] : "" : "";
                    var mainImage      = model.Image != null ? model.Image.Count >= i ? model.Image[i] : "" : "";
                    var secondaryImage = model.ImageBackground != null ? model.ImageBackground.Count >= i ? model.ImageBackground[i] : "" : "";
                    var order          = model.Order != null ? model.Order.Count >= i ? model.Order[i] : "1" : "1";

                    var keyPoint = new KeyPoint
                    {
                        Title                = title,
                        Description          = description,
                        Url                  = url,
                        MainImage            = mainImage,
                        SecondaryImage       = secondaryImage,
                        IsDeleted            = false,
                        CreationDate         = DateTime.Now,
                        Order                = Convert.ToInt32(order),
                        KeyPointsContainerId = keyPointContainer.KeyPointsContainerId
                    };

                    MagazineService.CreateKeyPoint(keyPoint);
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                return(View());
            }
            return(View());
        }