Пример #1
0
        /// <summary>
        /// <see cref="MyCompany.Expenses.Data.Repositories.IEmployeePictureRepository"/>
        /// </summary>
        /// <param name="employeePicture"><see cref="MyCompany.Expenses.Data.Repositories.IEmployeePictureRepository"/></param>
        /// <returns><see cref="MyCompany.Expenses.Data.Repositories.IEmployeePictureRepository"/></returns>
        public async Task <int> AddAsync(EmployeePicture employeePicture)
        {
            _context.EmployeePictures.Add(employeePicture);
            await _context.SaveChangesAsync();

            return(employeePicture.EmployeePictureId);
        }
        public object getImage(int employeeID)
        {
            db.Configuration.ProxyCreationEnabled = false;
            dynamic toReturn = new ExpandoObject();

            try
            {
                EmployeePicture image = db.EmployeePictures.Where(z => z.EmployeeID == employeeID).FirstOrDefault(); //
                if (image != null)
                {
                    // string path =  image.ImgName;
                    string path = System.IO.Path.Combine(HttpContext.Current.Server.MapPath("~/Images"), image.ImgName);
                    toReturn.Image = path;
                    //get pAppDomain.CurrentDomain.BaseDirectory + image.ImgName;
                }
                else
                {
                    toReturn.Message = "Image not available";
                }
            }
            catch (Exception)
            {
                toReturn.Message = "Failed to get image";
            }

            return(toReturn);
        }
Пример #3
0
        /// <summary>
        /// <see cref="MyCompany.Expenses.Data.Repositories.IEmployeePictureRepository"/>
        /// </summary>
        /// <param name="employeePicture"><see cref="MyCompany.Expenses.Data.Repositories.IEmployeePictureRepository"/></param>
        public async Task UpdateAsync(EmployeePicture employeePicture)
        {
            _context.Entry <EmployeePicture>(employeePicture)
            .State = EntityState.Modified;

            await _context.SaveChangesAsync();
        }
        /// <summary>
        /// <see cref="MyCompany.Vacation.Data.Repositories.IEmployeePictureRepository"/>
        /// </summary>
        /// <param name="employeePicture"><see cref="MyCompany.Vacation.Data.Repositories.IEmployeePictureRepository"/></param>
        public void Update(EmployeePicture employeePicture)
        {
            _context.Entry <EmployeePicture>(employeePicture)
            .State = EntityState.Modified;

            _context.SaveChanges();
        }
        /// <summary>
        /// <see cref="MyCompany.Visitors.Data.Repositories.IEmployeePictureRepository"/>
        /// </summary>
        /// <param name="employeePicture"><see cref="MyCompany.Visitors.Data.Repositories.IEmployeePictureRepository"/></param>
        public async Task UpdateAsync(EmployeePicture employeePicture)
        {
            if (employeePicture == null)
            {
                throw new ArgumentNullException("employeePicture");
            }

            _context.Entry <EmployeePicture>(employeePicture)
            .State = System.Data.Entity.EntityState.Modified;

            await _context.SaveChangesAsync();
        }
        /// <summary>
        /// <see cref="MyCompany.Visitors.Data.Repositories.IEmployeePictureRepository"/>
        /// </summary>
        /// <param name="employeePicture"><see cref="MyCompany.Visitors.Data.Repositories.IEmployeePictureRepository"/></param>
        /// <returns><see cref="MyCompany.Visitors.Data.Repositories.IEmployeePictureRepository"/></returns>
        public async Task <int> AddAsync(EmployeePicture employeePicture)
        {
            if (employeePicture == null)
            {
                throw new ArgumentNullException("employeePicture");
            }

            _context.EmployeePictures.Add(employeePicture);
            await _context.SaveChangesAsync();

            return(employeePicture.EmployeePictureId);
        }
Пример #7
0
        public MainWindow()
        {
            employee = new Employee()
            {
                Age         = 45,
                LastName    = "Seemann",
                Name        = "Mark",
                PicturePath = "images/Seemann.jpeg"
            };

            InitializeComponent();

            Binding pictureBinding = new Binding();

            pictureBinding.Source = employee;
            pictureBinding.Path   = new PropertyPath("PicturePath");

            EmployeePicture.SetBinding(Image.SourceProperty, pictureBinding);
        }
Пример #8
0
        public async Task EmployeePictureRepository_AddEmployeePicture_Added_NotFail_Test()
        {
            var context  = new MyCompanyContext();
            int expected = context.EmployeePictures.Count() + 1;

            var employeePictureId = context.EmployeePictures.Select(e => e.EmployeePictureId).Max() + 1;

            var employeePicture = new EmployeePicture()
            {
                EmployeePictureId = employeePictureId,
                EmployeeId        = 1,
                PictureType       = PictureType.Small,
                Content           = System.Text.Encoding.UTF8.GetBytes("sample"),
            };

            await target.AddAsync(employeePicture);

            int actual = context.EmployeePictures.Count();

            Assert.AreEqual(expected, actual);
        }
        public HttpResponseMessage uploadImage(int employeeID)
        {
            db.Configuration.ProxyCreationEnabled = false;
            try
            {
                string imageName   = null;
                var    httpRequest = HttpContext.Current.Request;

                //upload image
                var postedFile = httpRequest.Files["image"];

                //create custom filename
                imageName = new string(Path.GetFileNameWithoutExtension(postedFile.FileName).Take(10).ToArray()).Replace(" ", "-");
                imageName = imageName + DateTime.Now.ToString("yymmssff") + Path.GetExtension(postedFile.FileName);
                var filePath = HttpContext.Current.Server.MapPath("~/Images/" + imageName);
                postedFile.SaveAs(filePath);

                Employee employee = db.Employees.Where(z => z.EmployeeID == employeeID).FirstOrDefault();
                User     user     = db.Users.Where(z => z.UserID == employee.UserID).FirstOrDefault();
                //save to db
                using (OrdraDBEntities dbs = new OrdraDBEntities())
                {
                    EmployeePicture image = new EmployeePicture()
                    {
                        ImgCaption = user.UserName + " " + user.UserSurname + " Img",//httpRequest["ImageCaption"],
                        ImgName    = imageName,
                        EmployeeID = employeeID,
                    };
                    db.EmployeePictures.Add(image);
                    db.SaveChanges();
                }
            }
            catch (Exception error)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error in saving the image: " + error));
            }

            return(Request.CreateResponse(HttpStatusCode.Created, "Saved successfully"));
        }
        public void EmployeePictureRepository_AddEmployeePicture_Added_NotFail_Test()
        {
            var context  = new MyCompanyContext();
            int expected = context.EmployeePictures.Count() + 1;

            var target = new EmployeePictureRepository(context);

            var employeePictureId = context.EmployeePictures.Select(e => e.EmployeePictureId).Max() + 1;
            var employeeId        = context.Employees.FirstOrDefault().EmployeeId;

            var employeePicture = new EmployeePicture()
            {
                EmployeePictureId = employeePictureId,
                EmployeeId        = employeeId,
                PictureType       = PictureType.Small,
                Content           = System.Text.Encoding.UTF8.GetBytes("sample"),
            };

            target.Add(employeePicture);

            int actual = context.EmployeePictures.Count();

            Assert.AreEqual(expected, actual);
        }
 /// <summary>
 /// <see cref="MyCompany.Vacation.Data.Repositories.IEmployeePictureRepository"/>
 /// </summary>
 /// <param name="employeePicture"><see cref="MyCompany.Vacation.Data.Repositories.IEmployeePictureRepository"/></param>
 /// <returns><see cref="MyCompany.Vacation.Data.Repositories.IEmployeePictureRepository"/></returns>
 public int Add(EmployeePicture employeePicture)
 {
     _context.EmployeePictures.Add(employeePicture);
     _context.SaveChanges();
     return(employeePicture.EmployeePictureId);
 }
Пример #12
0
 public static UIImage ToImage(this EmployeePicture picture)
 {
     return(picture == null || picture.Content == null ? null : picture.Content.ToImage());
 }