Esempio n. 1
0
        public async Task AddAsync(int parentId, IFormFile image)
        {
            var account = await _accountService.GetAsync(parentId);

            var buffer = new byte[image.Length];

            image.OpenReadStream().Read(buffer, 0, (int)image.Length);

            var img = new AccountImage(buffer, image.ContentType);

            account.AccountImage = img;
            await _context.SaveChangesAsync();
        }
Esempio n. 2
0
        public void AddImage(AccountImage input, string id)
        {
            if (ContainsImage(id))
            {
                input.Id = GetImageId(id);
                _db.Update(input);
            }
            else
            {
                _db.Add(input);
            }

            _db.SaveChanges();
        }
Esempio n. 3
0
        public void AddDefaultImage(AccountImage acImg, string id)
        {
            acImg.Img = GetDefaultImageAsync();

            if (ContainsImage(id))
            {
                acImg.Id = GetImageId(id);
                _db.Update(acImg);
            }
            else
            {
                _db.Add(acImg);
            }

            _db.SaveChanges();
        }
Esempio n. 4
0
        public async Task <bool> ChangeImage(AccountViewModel input, string id)
        {
            using (var memoryStream = new MemoryStream())
            {
                await input.NewImage.CopyToAsync(memoryStream);

                var img = new AccountImage
                {
                    Img    = memoryStream.ToArray(),
                    UserId = id,
                };

                _userRepo.AddImage(img, id);

                return(true);
            }
        }
Esempio n. 5
0
    private void Load_Profile_Picture()
    {
        string sql = "SELECT * FROM USERS WHERE PROJECT_ID=" + Session["PROJECT_ID"].ToString() + " AND USER_NAME='" + Session["USER_NAME"].ToString() + "'";

        string FilePath = "";

        string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/";

        using (OracleConnection conn = WebTools.GetIpmsConnection())
        {
            using (OracleCommand cmd = new OracleCommand(sql, conn))
            {
                using (OracleDataReader dataReader = cmd.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        if (dataReader["ACCOUNT_PIC"] != DBNull.Value)
                        {
                            Random rnd = new Random();

                            string file_name = rnd.Next(1000, 9999).ToString() + "." + dataReader["ACCOUNT_PIC_EXT"];

                            FilePath = WebTools.SessionDataPath() + file_name;

                            if (File.Exists(FilePath))
                            {
                                File.Delete(FilePath);
                            }

                            byte[] byteArray = (Byte[])dataReader["ACCOUNT_PIC"];
                            using (FileStream fs = new FileStream(FilePath, FileMode.CreateNew, FileAccess.Write))
                            {
                                fs.Write(byteArray, 0, byteArray.Length);

                                AccountImage.ImageUrl = baseUrl + "SessionData/" + Session.SessionID.ToString() + @"/" + file_name;
                                AccountImage.DataBind();
                            }
                        }
                    }
                }
            }
        }
    }