Ejemplo n.º 1
0
        // Attention - 08 - Add photo to an existing for-sale property
        // This works like a typical add/edit Manager class method
        // that has an associated object
        public PropertyBase PropertyPhotoAdd(PhotoAdd newItem)
        {
            // Validate the associated item
            var a = ds.Properties.Find(newItem.PropertyId);

            if (a == null)
            {
                return(null);
            }
            else
            {
                // Attempt to add the new item
                var addedItem = new Photo();
                ds.Photos.Add(addedItem);

                addedItem.Caption  = newItem.Caption;
                addedItem.Property = a;

                // Handle the uploaded photo...

                // First, extract the bytes from the HttpPostedFile object
                byte[] photoBytes = new byte[newItem.PhotoUpload.ContentLength];
                newItem.PhotoUpload.InputStream.Read(photoBytes, 0, newItem.PhotoUpload.ContentLength);

                // Then, configure the new object's properties
                addedItem.Content     = photoBytes;
                addedItem.ContentType = newItem.PhotoUpload.ContentType;

                ds.SaveChanges();

                return((addedItem == null) ? null : Mapper.Map <PropertyBase>(a));
            }
        }
Ejemplo n.º 2
0
        public ActionResult AddPhoto(int?id, PhotoAdd newItem)
        {
            // Validate the input
            // Two conditions must be checked
            if (!ModelState.IsValid && id.GetValueOrDefault() == newItem.PropertyId)
            {
                return(View(newItem));
            }

            // Process the input
            var addedItem = m.PropertyPhotoAdd(newItem);

            if (addedItem == null)
            {
                return(View(newItem));
            }
            else
            {
                return(RedirectToAction("Details", new { id = addedItem.Id }));
            }
        }
Ejemplo n.º 3
0
        // Attention - 08 - Add photo to an existing for-sale property
        // This works like a typical add/edit Manager class method
        // that has an associated object
        public PropertyBase PropertyPhotoAdd(PhotoAdd newItem)
        {
            // Validate the associated item
            var a = ds.Properties.Find(newItem.PropertyId);

            if (a == null)
            {
                return null;
            }
            else
            {
                // Attempt to add the new item
                var addedItem = new Photo();
                ds.Photos.Add(addedItem);

                addedItem.Caption = newItem.Caption;
                addedItem.Property = a;

                // Handle the uploaded photo...

                // First, extract the bytes from the HttpPostedFile object
                byte[] photoBytes = new byte[newItem.PhotoUpload.ContentLength];
                newItem.PhotoUpload.InputStream.Read(photoBytes, 0, newItem.PhotoUpload.ContentLength);

                // Then, configure the new object's properties
                addedItem.Content = photoBytes;
                addedItem.ContentType = newItem.PhotoUpload.ContentType;

                ds.SaveChanges();

                return (addedItem == null) ? null : Mapper.Map<PropertyBase>(a);
            }
        }
        public ActionResult AddPhoto(int? id, PhotoAdd newItem)
        {
            // Validate the input
            // Two conditions must be checked
            if (!ModelState.IsValid && id.GetValueOrDefault() == newItem.PropertyId)
            {
                return View(newItem);
            }

            // Process the input
            var addedItem = m.PropertyPhotoAdd(newItem);

            if (addedItem == null)
            {
                return View(newItem);
            }
            else
            {
                return RedirectToAction("Details", new { id = addedItem.Id });
            }
        }