示例#1
0
        public static FreeMarketResult SaveDepartmentImage(int departmentNumber, PictureSize size, HttpPostedFileBase image)
        {
            if (image != null && departmentNumber != 0)
            {
                using (FreeMarketEntities db = new FreeMarketEntities())
                {
                    DepartmentPicture picture = new DepartmentPicture();

                    Department department = db.Departments.Find(departmentNumber);

                    if (department == null)
                    {
                        return(FreeMarketResult.Failure);
                    }

                    picture = db.DepartmentPictures
                              .Where(c => c.DepartmentNumber == departmentNumber && c.Dimensions == size.ToString())
                              .FirstOrDefault();

                    try
                    {
                        // No picture exists for this dimension/product
                        if (picture == null)
                        {
                            picture            = new DepartmentPicture();
                            picture.Picture    = new byte[image.ContentLength];
                            picture.Annotation = department.DepartmentName;
                            picture.Dimensions = size.ToString();
                            image.InputStream.Read(picture.Picture, 0, image.ContentLength);
                            picture.PictureMimeType  = image.ContentType;
                            picture.DepartmentNumber = departmentNumber;

                            db.DepartmentPictures.Add(picture);
                            db.SaveChanges();

                            AuditUser.LogAudit(9, string.Format("Department: {0}", departmentNumber));
                            return(FreeMarketResult.Success);
                        }
                        else
                        {
                            picture.Annotation = department.DepartmentName;
                            picture.Picture    = new byte[image.ContentLength];
                            image.InputStream.Read(picture.Picture, 0, image.ContentLength);
                            picture.PictureMimeType = image.ContentType;

                            db.Entry(picture).State = EntityState.Modified;
                            db.SaveChanges();

                            AuditUser.LogAudit(9, string.Format("Department: {0}", departmentNumber));
                            return(FreeMarketResult.Success);
                        }
                    }
                    catch (Exception e)
                    {
                        ExceptionLogging.LogException(e);
                        return(FreeMarketResult.Failure);
                    }
                }
            }

            return(FreeMarketResult.Failure);
        }
        public async Task <Uri> GetSkydriveItemPictureAsync(String skyDriveItemId, PictureSize pictureSize)
        {
            // requires wl.skydrive scope
            var client          = new LiveConnectClient(_session);
            var path            = String.Format("{0}/picture?type={1}", skyDriveItemId, pictureSize.ToString().ToLowerInvariant());
            var operationResult = await client.GetAsync(path);

            dynamic result   = operationResult.Result;
            var     imageUrl = new Uri(result.location.ToString());

            return(imageUrl);
        }
示例#3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     Content.Style.Add(HtmlTextWriterStyle.Width, PictureSize.ToString());
     Content.Style.Add(HtmlTextWriterStyle.Height, PictureSize.ToString());
 }