public async Task <ActionResult> Create(ImageEditViewModel model)
        {
            if (DoesCodeAlreadyExist(model.Image))
            {
                ModelState.AddModelError("Image.ImageCode", ImageStrings.CodeAlreadyExists);
            }

            if (ModelState.IsValid)
            {
                if (model.ImageUpload != null)
                {
                    var fileName = Guid.NewGuid().ToString();
                    var path     = Server.MapPath("~/Public/Images/");

                    FileUploadHelper.GenerateVersions(model.ImageUpload.InputStream, path + fileName);

                    model.Image.ImageUrl = fileName;
                }

                model.Image.Keywords =
                    db.Set <Keyword>()
                    .Where(kw => model.KeywordIds.Contains(kw.Id))
                    .ToList();

                db.Add(model.Image);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            model.PopulateDropDownLists(db.Set <Document>(), db.Set <Classification>(), db.Set <Keyword>());

            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Create(KeywordTranslation kt)
        {
            if (DoesKeywordExist(kt))
            {
                ModelState.AddModelError("Value", KeywordStrings.Validation_AlreadyExists);
            }

            if (ModelState.IsValid)
            {
                var keyword = new Keyword();
                keyword.Translations.Add(kt);

                db.Add(keyword);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(kt));
        }
        public async Task <ActionResult> Create(ReferencedLink referencedlink)
        {
            if (ModelState.IsValid)
            {
                db.Add(referencedlink);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(referencedlink));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Create(ProcessTranslation pt)
        {
            if (DoesProcessExist(pt))
            {
                ModelState.AddModelError("Value", ProcessStrings.Validation_AlreadyExists);
            }

            if (ModelState.IsValid)
            {
                var process = new Process();
                process.Translations.Add(pt);

                db.Add(process);

                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(pt));
        }
Exemplo n.º 5
0
        public async Task <ActionResult> Create(ClassificationTranslation classification)
        {
            if (DoesClassificationExist(classification))
            {
                ModelState.AddModelError("Value", ClassificationStrings.ValError_AlreadyExists);
            }


            if (ModelState.IsValid)
            {
                var c = new Classification();

                c.Translations.Add(classification);

                db.Add(c);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(classification));
        }
        public async Task <ActionResult> Create(Specimen specimen)
        {
            if (DoesCodeAlreadyExist(specimen))
            {
                ModelState.AddModelError("ReferenceCode", SpecimenStrings.CodeAlreadyExists);
            }

            if (ModelState.IsValid)
            {
                db.Add(specimen);

                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(GenerateViewModel(specimen)));
        }
        public async Task <ActionResult> Create(CollectionEditViewModel model)
        {
            if (DoesCodeAlreadyExist(model.Collection))
            {
                ModelState.AddModelError("Collection.CatalogCode", CollectionStrings.Validation_CodeAlreadyExists);
            }

            if (ModelState.IsValid)
            {
                if (model.Logo != null)
                {
                    var newName = Guid.NewGuid().ToString() + ".jpg";

                    FileUploadHelper.SaveImage(model.Logo.InputStream,
                                               400, 400,
                                               Server.MapPath("~/Public/Collections/") + newName,
                                               FitMode.Crop);

                    model.Collection.LogoLocation = newName;
                }

                var authors = db.Set <Author>()
                              .Where(a => model.AuthorIds.Contains(a.Id));

                model.Collection.Authors = authors.ToList();

                db.Add(model.Collection);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            model.AvailableAuthors = db.Set <Author>()
                                     .Select(a => new SelectListItem
            {
                Value    = a.Id.ToString(),
                Text     = a.LastName + ", " + a.FirstName,
                Selected = model.AuthorIds.Contains(a.Id)
            })
                                     .ToList();

            return(View(model));
        }
        public async Task <ActionResult> Create(ShowcasePhoto showcasePhoto)
        {
            var image = db.Set <Image>().FirstOrDefault(i => i.Id == showcasePhoto.ImageId);

            if (!image.IsVisible)
            {
                ModelState.AddModelError("ImageId", ShowcasePhotoStrings.ValidationError_ImageHidden);
            }

            if (ModelState.IsValid)
            {
                db.Add(showcasePhoto);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(GenerateViewModel(showcasePhoto)));
        }
        public async Task <ActionResult> Create(Document document)
        {
            if (DoesCodeAlreadyExist(document))
            {
                ModelState.AddModelError("CatalogCode", DocumentStrings.CodeAlreadyExists);
            }

            if (ModelState.IsValid)
            {
                db.Add(document);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            var model = new DocumentEditViewModel(document);
            await model.PopulateDropDownLists(db.Set <Author>(), db.Set <Collection>());

            return(View(model));
        }
Exemplo n.º 10
0
        public async Task <ActionResult> Create(NewsItemViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.HeaderImageUpload != null)
                {
                    var fileName = Guid.NewGuid().ToString();
                    var path     = Server.MapPath("~/Public/News/");

                    FileUploadHelper.GenerateVersions(model.HeaderImageUpload.InputStream, path + fileName);

                    model.NewsItem.HeaderImage = fileName;
                }

                db.Add(model.NewsItem);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(GenerateViewModel(model.NewsItem)));
        }
        public async Task <ActionResult> Create(EventEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.Attachments != null)
                {
                    foreach (var attachment in model.Attachments)
                    {
                        var attachedFile = model.Files.FirstOrDefault(f => f.FileName == attachment.FileName);

                        if (attachedFile != null)
                        {
                            var newName = Guid.NewGuid().ToString() + "_" + Path.GetExtension(attachedFile.FileName);
                            var dir     = "~/Public/Attachments/";

                            Directory.CreateDirectory(Server.MapPath(dir));

                            attachedFile.SaveAs(Server.MapPath(dir + newName));

                            model.Event.Attachments.Add(new Attachment
                            {
                                FileName   = newName,
                                MimeFormat = attachedFile.ContentType,
                                Size       = attachedFile.ContentLength,
                                Title      = attachment.Title
                            });
                        }
                    }
                }

                db.Add(model.Event);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
        public async Task <ActionResult> Create(BannerPhotographEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var newName = Guid.NewGuid().ToString() + Path.GetExtension(model.Image.FileName);

                FileUploadHelper.SaveImage(
                    model.Image.InputStream,
                    1024,
                    500,
                    Path.Combine(Server.MapPath("~/Public/Banners"), newName),
                    FitMode.Crop);

                model.Banner.UriPath = newName;

                db.Add(model.Banner);

                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
        public async Task <ActionResult> Create(AuthorEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.ImageUpload != null)
                {
                    var newName = Guid.NewGuid().ToString() + ".jpg";

                    FileUploadHelper.SaveImage(model.ImageUpload.InputStream,
                                               400, 400,
                                               Server.MapPath("~/Public/Authors/") + newName,
                                               FitMode.Crop);

                    model.Author.PictureFileName = newName;
                }

                db.Add(model.Author);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }