Exemplo n.º 1
0
        public ActionResult Create(Event model, IEnumerable<HttpPostedFileBase> files, IEnumerable<HttpPostedFileBase> filesAnother, FormCollection form)
        {
            try
            {
                var ev = new Event
                {
                    Title = model.Title,
                    TitleEn = model.TitleEn,
                    TitleUa = model.TitleUa,
                    TitleDescription = model.TitleDescription,
                    TitleDescriptionEn = model.TitleDescriptionEn,
                    TitleDescriptionUa = model.TitleDescriptionUa,
                    Date = model.Date,
                    HighlightedText = model.HighlightedText,
                    HighlightedTextEn = model.HighlightedTextEn,
                    HighlightedTextUa = model.HighlightedTextUa,
                    LocationAddress  = model.LocationAddress,
                    LocationAddressEn  = model.LocationAddressEn,
                    LocationAddressUa  = model.LocationAddressUa,
                    LocationAddressMapUrl = model.LocationAddressMapUrl,
                    LocationTitle = model.LocationTitle,
                    LocationTitleEn = model.LocationTitleEn,
                    LocationTitleUa = model.LocationTitleUa,
                    TicketOrderType = model.TicketOrderType,
                    PreviewContentType = model.PreviewContentType,
                    ArtGroup = model.ArtGroup,
                    ArtGroupEn = model.ArtGroupEn,
                    ArtGroupUa = model.ArtGroupUa,
                    Action = model.Action,
                    ActionEn = model.ActionEn,
                    ActionUa = model.ActionUa,
                    Location = model.Location,
                    LocationEn = model.LocationEn,
                    LocationUa = model.LocationUa,
                    Duration = model.Duration,
                    Description = model.Description,
                    DescriptionEn = model.DescriptionEn,
                    DescriptionUa = model.DescriptionUa,
                    IntervalQuantity = model.IntervalQuantity,
                    PreviewContentVideoSrc = model.PreviewContentVideoSrc,
                    Price = model.Price
                };

                ev.IsHighlighted = !string.IsNullOrEmpty(ev.HighlightedText);

                foreach (var file in files)
                {
                    if (file == null) continue;
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                    string filePath = Server.MapPath("~/Content/Images");

                    filePath = Path.Combine(filePath, fileName);

                    // h: 283
                    // w: 400
                    GraphicsHelper.SaveOriginalImageWithDefinedDimentions(filePath, fileName, file, 400, 283, ScaleMode.Crop);

                    var ci = new ContentImage
                    {
                        ImageSrc = fileName
                    };

                    ev.ContentImages.Add(ci);
                }

                foreach (var file in filesAnother)
                {
                    if (file == null) continue;
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                    string filePath = Server.MapPath("~/Content/Images");

                    filePath = Path.Combine(filePath, fileName);
                    //GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500);
                    GraphicsHelper.SaveOriginalImageWithDefinedDimentions(filePath, fileName, file, 788, 500, ScaleMode.Crop);

                    var ci = new PreviewContentImage
                    {
                        ImageSrc = fileName
                    };

                    ev.PreviewContentImages.Add(ci);
                }

                PostCheckboxesData attrData = form.ProcessPostCheckboxesData("author");

                foreach (var kvp in attrData)
                {
                    var tagId = kvp.Key;
                    bool tagValue = kvp.Value;

                    //author.Tags.Clear();

                    if (tagValue)
                    {
                        var author = _context.Authors.First(t => t.Id == tagId);
                        ev.Authors.Add(author);
                    }
                }


                _context.Events.Add(ev);
                _context.SaveChanges();
                
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Exemplo n.º 2
0
        public ActionResult Edit(int id, IEnumerable<HttpPostedFileBase> files, IEnumerable<HttpPostedFileBase> filesAnother, FormCollection form)
        {
            try
            {
                var ev = _context.Events.First(e => e.Id == id);
                TryUpdateModel(ev, new[]
                {
                    "Title",
                    "TitleEn",
                    "TitleUa",
                    "TitleDescription",
                    "TitleDescriptionEn",
                    "TitleDescriptionUa",
                    "Date",
                    "HighlightedText",
                    "HighlightedTextEn",
                    "HighlightedTextUa",
                    "LocationAddress",
                    "LocationAddressEn",
                    "LocationAddressUa",
                    "HighlightedText",
                    "HighlightedTextEn",
                    "HighlightedTextUa",
                    "LocationAddress",
                    "LocationAddressEn",
                    "LocationAddressUa",
                    "LocationAddressMapUrl",
                    "LocationTitle",
                    "LocationTitleEn",
                    "LocationTitleUa",
                    "TicketOrderType",
                    "PreviewContentType",
                    "ArtGroup",
                    "ArtGroupEn",
                    "ArtGroupUa",
                    "Action",
                    "ActionEn",
                    "ActionUa",
                    "Location",
                    "LocationEn",
                    "LocationUa",
                    "Duration",
                    "Description",
                    "DescriptionEn",
                    "DescriptionUa",
                    "IntervalQuantity",
                    "PreviewContentVideoSrc",
                    "Price"
                });

                ev.IsHighlighted = !string.IsNullOrEmpty(ev.HighlightedText);


                foreach (var file in files)
                {
                    if (file == null) continue;
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                    string filePath = Server.MapPath("~/Content/Images");

                    filePath = Path.Combine(filePath, fileName);
                    //GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500);
                    GraphicsHelper.SaveOriginalImageWithDefinedDimentions(filePath, fileName, file, 400, 283,ScaleMode.Crop);

                    var ci = new ContentImage
                    {
                        ImageSrc = fileName
                    };

                    ev.ContentImages.Add(ci);
                }

                foreach (var file in filesAnother)
                {
                    if (file == null) continue;
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                    string filePath = Server.MapPath("~/Content/Images");

                    filePath = Path.Combine(filePath, fileName);
                    //GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500);
                    GraphicsHelper.SaveOriginalImageWithDefinedDimentions(filePath, fileName, file, 788, 500, ScaleMode.Crop);

                    var ci = new PreviewContentImage
                    {
                        ImageSrc = fileName
                    };

                    ev.PreviewContentImages.Add(ci);
                }

                PostCheckboxesData attrData = form.ProcessPostCheckboxesData("author");

                ev.Authors.Clear();

                foreach (var kvp in attrData)
                {
                    var tagId = kvp.Key;
                    bool tagValue = kvp.Value;

                    //author.Tags.Clear();

                    if (tagValue)
                    {
                        var author = _context.Authors.First(t => t.Id == tagId);
                        ev.Authors.Add(author);
                    }
                }

                _context.SaveChanges();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }