Exemplo n.º 1
0
        public ActionResult GalleryEdit(GalleryEdit galEdit, string hdnPreviewPhotosShadow, string hdnPhotosShadow, string hdnTrashShadow, string hdnIsRootGallery)
        {
            var allOk = true;
            if (ModelState.IsValid)
            {
                try
                {
                    var gal = new Gallery
                        {
                            DateCreated = DateTime.Now,
                            Name = galEdit.Name,
                            Description = galEdit.Description,
                            Order = galEdit.Order,
                            Year = galEdit.Year,
                            OwnerId = UserSession.OwnerId,
                            GalleryType = (int)GalleryTypes.Content
                        };

                    if (galEdit.ParentGalleryId == "0")
                    {
                        gal.ParentId = null;
                    }
                    else
                    {
                        gal.ParentId = int.Parse(galEdit.ParentGalleryId);
                    }

                    if (galEdit.PreviewGallery)
                    {
                        gal.GalleryType = (int) GalleryTypes.Preview;
                    }

                    if (hdnIsRootGallery.ToLower() == "true")
                    {
                        gal.GalleryType = (int) GalleryTypes.Root;
                    }

                    if (galEdit.GalleryId.HasValue) //UPDATE
                    {
                        gal.GalleryId = galEdit.GalleryId.Value;
                        gal = ProcessGalleryPhotos(gal, hdnPreviewPhotosShadow, hdnPhotosShadow, hdnTrashShadow);
                        GalleryService.Update(gal);
                        galEdit.AddOKMessage(string.Format("Update galerie {0} proběhl úspěšně.", gal.Name));
                    }
                    else //INSERT
                    {
                        var newId = GalleryService.Insert(gal);
                        galEdit.AddOKMessage(string.Format("Uložení nové galerie {0} proběhlo úspěšně.", gal.Name));
                        galEdit.GalleryId = newId;
                    }
                }
                catch (Exception ex)
                {
                    allOk = false;
                    galEdit.AddErrorMessage("Při ukládání galerie došlo k chybě: " + ex.Message);
                }
            }
            else
            {
                allOk = false;
                galEdit.AddErrorMessage("Některá povinná položka není vyplněná.");
            }

            GalleryEdit retModel;

            if (allOk)
            {
                var editedGallery = GalleryService.GetById(galEdit.GalleryId.Value);
                retModel = MapGalleryToGalleryEdit(editedGallery);
            }
            else
            {
                retModel = galEdit;
            }

            if(galEdit.ErrorMessages.Count > 0)
            {
                foreach (var errorMessage in galEdit.ErrorMessages)
                {
                    retModel.AddErrorMessage(errorMessage);
                }
            }

            if(galEdit.OKMessages.Count > 0)
            {
                foreach(var okMessage in galEdit.OKMessages)
                {
                    retModel.AddOKMessage(okMessage);
                }
            }

            return View(retModel);
        }
Exemplo n.º 2
0
        public ActionResult GalleryEdit(string Id)
        {
            GalleryEdit retModel;
            int galleryId;

            var tempModel = TempData["result"] as MessageTransferModel;

            if (int.TryParse(Id, out galleryId))
            {
                var gal = GalleryService.GetById(galleryId);
                retModel = MapGalleryToGalleryEdit(gal);
            }
            else
            {
                retModel = new GalleryEdit { GalleryList = GetListForGalleryInsert() };
            }

            if(tempModel != null)
            {
                retModel.CopyMessages(tempModel);
            }

            return View(retModel);
        }