public ActionResult Create(VehicleAdd newItem)
        {
            // Validate the input
            if (!ModelState.IsValid)
            {
                return View(newItem);
            }

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

            if (addedItem == null)
            {
                return View(newItem);
            }
            else
            {
                return RedirectToAction("Details", new { id = addedItem.Id });
            }
        }
Exemplo n.º 2
0
        public ActionResult Create(VehicleAdd newItem)
        {
            // Validate the input
            if (!ModelState.IsValid)
            {
                return(View(newItem));
            }

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

            if (addedItem == null)
            {
                return(View(newItem));
            }
            else
            {
                return(RedirectToAction("Details", new { id = addedItem.Id }));
            }
        }
Exemplo n.º 3
0
        public VehicleBase VehicleAdd(VehicleAdd newItem)
        {
            // Attempt to add the new item
            var addedItem = ds.Vehicles.Add(mapper.Map <Vehicle>(newItem));

            // At this time, the value of the PhotoUpload property should be non-null
            // That was defined by a [Required] attribute in the view model class

            // Attention - 6 - 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.Photo            = photoBytes;
            addedItem.PhotoContentType = newItem.PhotoUpload.ContentType;

            ds.SaveChanges();

            return((addedItem == null) ? null : mapper.Map <VehicleBase>(addedItem));
        }
Exemplo n.º 4
0
        public VehicleBase VehicleAdd(VehicleAdd newItem)
        {
            // Attempt to add the new item
            var addedItem = ds.Vehicles.Add(Mapper.Map<Vehicle>(newItem));

            // At this time, the value of the PhotoUpload property should be non-null
            // That was defined by a [Required] attribute in the view model class

            // Attention - 6 - 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.Photo = photoBytes;
            addedItem.PhotoContentType = newItem.PhotoUpload.ContentType;
            
            ds.SaveChanges();

            return (addedItem == null) ? null : Mapper.Map<VehicleBase>(addedItem);
        }