Exemplo n.º 1
0
        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."];
            }));
        }
Exemplo n.º 2
0
 public IActionResult Current([FromServices] ICultureProvider _cultureProvider)
 {
     return(Content(_cultureProvider.DetermineCulture()));
 }