public ActionResult Create(Photo photo, IEnumerable <HttpPostedFileBase> files) { if (files.Count() == 0 || files.FirstOrDefault() == null) { ViewBag.error = "Please choose a file"; return(View(photo)); } if (ModelState.IsValid) { Photo model = new Photo(); foreach (var file in files) { model.Description = photo.Description; var fileName = Guid.NewGuid().ToString(); var extension = System.IO.Path.GetExtension(file.FileName).ToLower(); model.ThumbPath = string.Format("/Content/images/thumbnail/{0}{1}", fileName, extension); model.ImagePath = string.Format("/Content/images/{0}{1}", fileName, extension); using (var img = System.Drawing.Image.FromStream(file.InputStream)) { // Save thumbnail size image, 100 x 100 SaveToFolder(img, fileName, extension, new Size(100, 100), model.ThumbPath); // Save large size image, 800 x 800 SaveToFolder(img, fileName, extension, new Size(800, 800), model.ImagePath); } galleryDb.Photos.Add(model); galleryDb.SaveChanges(); } } return(RedirectPermanent("/home")); }
/// <summary> /// Operations to be performed during the downgrade process. /// </summary> public override void Down() { using (var ctx = new GalleryDb()) { var asDataSchema = ctx.AppSettings.First(a => a.SettingName == "DataSchemaVersion"); asDataSchema.SettingValue = "3.0.1"; ctx.SaveChanges(); } }
/// <summary> /// Operations to be performed during the downgrade process. /// </summary> public override void Down() { using (var ctx = new GalleryDb()) { var asDataSchema = ctx.AppSettings.First(a => a.SettingName == "DataSchemaVersion"); asDataSchema.SettingValue = "3.0.0"; ctx.SaveChanges(); } }
public override void Down() { DropIndex("gsp.Metadata", "UC_Metadata_MetaName_MetadataId"); AlterColumn("gsp.Metadata", "RawValue", c => c.String(maxLength: 1000)); using (var ctx = new GalleryDb()) { var asDataSchema = ctx.AppSettings.First(a => a.SettingName == "DataSchemaVersion"); asDataSchema.SettingValue = "3.1.0"; ctx.SaveChanges(); } }
public override void Down() { DropIndex("gsp.Metadata", "UC_Metadata_MetaName_MetadataId"); AlterColumn("gsp.Metadata", "RawValue", c => c.String(maxLength: 1000)); using (var ctx = new GalleryDb()) { var asDataSchema = ctx.AppSettings.First(a => a.SettingName == "DataSchemaVersion"); asDataSchema.SettingValue = "3.1.0"; ctx.SaveChanges(); } }
public override void Down() { DropColumn("gsp.Metadata", "RawValue"); DropColumn("gsp.MediaQueue", "ConversionType"); DropColumn("gsp.MediaQueue", "RotationAmount"); AddColumn("gsp.MediaObject", "HashKey", c => c.String(nullable: false, maxLength: 47)); using (var ctx = new GalleryDb()) { var asDataSchema = ctx.AppSettings.First(a => a.SettingName == "DataSchemaVersion"); asDataSchema.SettingValue = "3.0.3"; ctx.SaveChanges(); } }
public override void Down() { DropColumn("gsp.Metadata", "RawValue"); DropColumn("gsp.MediaQueue", "ConversionType"); DropColumn("gsp.MediaQueue", "RotationAmount"); AddColumn("gsp.MediaObject", "HashKey", c => c.String(nullable: false, maxLength: 47)); using (var ctx = new GalleryDb()) { var asDataSchema = ctx.AppSettings.First(a => a.SettingName == "DataSchemaVersion"); asDataSchema.SettingValue = "3.0.3"; ctx.SaveChanges(); } }
/// <summary> /// Operations to be performed during the downgrade process. /// </summary> public override void Down() { AddColumn("gsp.Album", "DateEnd", c => c.DateTime()); AddColumn("gsp.Album", "DateStart", c => c.DateTime()); // Don't actually reduce column length to 10 chars, since we'll lose data //DropIndex("gsp.MimeType", "UC_MimeType_FileExtension"); //AlterColumn("gsp.MimeType", "FileExtension", c => c.String(nullable: false, maxLength: 10)); //CreateIndex("gsp.MimeType", "FileExtension", true, "UC_MimeType_FileExtension"); using (var ctx = new GalleryDb()) { var asDataSchema = ctx.AppSettings.First(a => a.SettingName == "DataSchemaVersion"); asDataSchema.SettingValue = "3.2.1"; ctx.SaveChanges(); } }
protected virtual IAsyncAction InitOverrideAsync() { return(Task.Run(() => { using (var db = new GalleryDb()) { var gid = Id; var myModel = db.GallerySet.SingleOrDefault(model => model.GalleryModelId == gid); if (myModel is null) { db.GallerySet.Add(new GalleryModel().Update(this)); } else { myModel.Update(this); } db.SaveChanges(); } }).AsAsyncAction()); }