public async Task <IActionResult> CreateCertificate(Certificate Model, IFormFile File) { if (File != null && File.Length > 0) { var file = new Pomelo.AspNetCore.Extensions.BlobStorage.Models.Blob { Bytes = await File.ReadAllBytesAsync(), ContentLength = File.Length, FileName = File.FileName, ContentType = File.ContentType, Time = DateTime.Now }; DB.Blobs.Add(file); await DB.SaveChangesAsync(); Model.BlobId = file.Id; } DB.Certificates.Add(Model); await DB.SaveChangesAsync(); return(Prompt(x => { x.Title = SR["Succeeded"]; x.Details = SR["Certificate has been created successfully."]; x.HideBack = true; x.RedirectText = SR["Back To Certificate List"]; x.RedirectUrl = Url.Action("Certificate", "Admin"); })); }
public async Task <IActionResult> Profile(Profile Model, string _name, string _position, string _selfIntroduce, IFormFile Avatar, [FromServices] ICultureProvider cultureProvider) { var key = cultureProvider.DetermineCulture(); Model.AvatarId = Startup.Profile.AvatarId; Model.Name = Startup.Profile.Name; Model.Position = Startup.Profile.Position; Model.SelfIntroduce = Startup.Profile.SelfIntroduce; if (Model.Name.ContainsKey(key)) { Model.Name.Remove(key); } if (Model.Position.ContainsKey(key)) { Model.Position.Remove(key); } if (Model.SelfIntroduce.ContainsKey(key)) { Model.SelfIntroduce.Remove(key); } Model.Name.Add(key, _name); Model.Position.Add(key, _position); Model.SelfIntroduce.Add(key, _selfIntroduce); if (Avatar != null && Avatar.Length > 0) { var blob = new Pomelo.AspNetCore.Extensions.BlobStorage.Models.Blob { Bytes = await Avatar.ReadAllBytesAsync(), FileName = Avatar.FileName, ContentLength = Avatar.Length, Time = DateTime.Now, ContentType = Avatar.ContentType }; DB.Blobs.Add(blob); DB.SaveChanges(); Model.AvatarId = blob.Id; } Startup.Profile = Model; System.IO.File.WriteAllText("profile.json", JsonConvert.SerializeObject(Model)); return(Prompt(x => { x.Title = SR["Succeeded"]; x.Details = SR["Your profile has been saved successfully."]; })); }