Пример #1
0
        public PartialViewResult Upload(int x, int y)
        {
            var model = new UploadModel {X = x, Y = y};

            return PartialView(model);
        }
Пример #2
0
        public ActionResult Upload(UploadModel model)
        {
            if (!model.File.IsImage())
            {
                model.IsSuccessful = false;
                model.ErrorMessage = "Image type not recognized!";
            }
            else
            {
                var image = Image.FromStream(model.File.InputStream, true, true);

                if (GetImage(model.X, model.Y) != null)
                {
                    model.IsSuccessful = false;
                    model.ErrorMessage = "Tile already taken!";
                }
                else if (image.Width != 64 || image.Height != 64)
                {
                    if (!model.Resize)
                    {
                        model.IsSuccessful = false;
                        model.ErrorMessage = "Image dimensions not supported (64 x 64 required).  Would you like to resize?";
                    }
                    else
                    {
                        image = image.ResizeImage(64);
                    }
                }

                if (model.IsSuccessful.IsNotFalse())
                {
                    model.IsSuccessful = true;
                    image.Save("~/UploadedImages/Current/".ToMapPath() + model.X + "-" + model.Y + ".png");
                    CompletionService.Run();

                    model.ImageUrl = GetImage(model.X, model.Y, true).FullName.RemoveBefore("\\UploadedImages\\");
                }
            }

            return PartialView(model);
        }