public async Task <ActionResult> Create(StoreItemImageDto storeItemImage, HttpPostedFileBase storeItemImageFile)
        {
            StoreItemImageDto newstoreItemImage = new StoreItemImageDto();

            newstoreItemImage.Id           = storeItemImage.Id;
            newstoreItemImage.StoreItem    = storeItemImage.StoreItem;
            newstoreItemImage.CreatedDate  = DateTime.Now;
            newstoreItemImage.ModifiedDate = DateTime.Now;

            if (ModelState.IsValid)
            {
                var request = new HTTPrequest();
                //HttpPostedFileBase newFile = Request.Files["storeItemImageFile"];
                //HttpPostedFileBase newFile = storeItemImageFile;
                if (storeItemImageFile != null && storeItemImageFile.ContentLength > 0)
                {
                    storeItemImage.Image = new byte[storeItemImageFile.ContentLength];
                    storeItemImageFile.InputStream.Read(storeItemImage.Image, 0, storeItemImageFile.ContentLength);
                    string fileExtension = Path.GetExtension(storeItemImageFile.FileName);
                    storeItemImage.FileType = fileExtension;
                    if (storeItemImageFile == null)
                    {
                        throw new ArgumentException("file");
                    }
                }

                await request.Post <StoreItemImageDto>("api/storeItemImage", storeItemImage);

                return(RedirectToAction("Index"));
            }
            return(View(storeItemImage));
        }
Beispiel #2
0
        public async Task <ActionResult> Create(StoreItemDto storeItem, HttpPostedFileBase imageFile)
        {
            // Checks Name is not Null or Empty
            if (string.IsNullOrEmpty(storeItem.Name))
            {
                ViewBag.ValidationName = "Name field is required.";
                return(View(storeItem));
            }
            StoreItemDto newStoreItem = new StoreItemDto();

            newStoreItem.Id           = storeItem.Id;
            newStoreItem.Name         = storeItem.Name;
            newStoreItem.Description  = storeItem.Description;
            newStoreItem.ModifiedDate = storeItem.ModifiedDate;
            newStoreItem.InStock      = storeItem.InStock;
            newStoreItem.Cost         = storeItem.Cost;

            if (ModelState.IsValid)
            {
                var request = new HTTPrequest();
                storeItem = await request.Post <StoreItemDto>("api/storeItem", storeItem);

                return(RedirectToAction("Index", new { recentAction = "Created", recentName = storeItem.Name, recentId = storeItem.Id }));
            }
            else
            {
                var request = new HTTPrequest();
                return(View());
            }
        }
Beispiel #3
0
        public async Task <ActionResult> Create(ArtefactCategoryDto category, HttpPostedFileBase imageFile)
        {
            if (string.IsNullOrEmpty(category.Name))
            {
                ViewBag.ValidationName = "Name field is required.";
                return(View(category));
            }

            if (ModelState.IsValid)
            {
                var request = new HTTPrequest();

                HttpPostedFileBase imgFile = Request.Files["ImageFile"];
                if (imgFile != null)
                {
                    category.Image = new byte[imgFile.ContentLength];
                    imgFile.InputStream.Read(category.Image, 0, imgFile.ContentLength);
                }

                category = await request.Post <ArtefactCategoryDto>("api/artefactCatergory", category);

                return(RedirectToAction("Index", new { recentAction = "Created", recentName = category.Name, recentId = category.Id }));
            }

            return(View(category));
        }
        public async Task <ActionResult> Create(ArtefactDto artefact, HttpPostedFileBase imageFile)
        {
            // ARTEFACT CATEGORY DROPDOWN
            List <SelectListItem> categoryDropdown = new List <SelectListItem>();

            categoryDropdown = await PopulateCategoryDropdown();

            ViewBag.CategoryList = categoryDropdown;

            // ARTEFACT ZONE DROPDOWN
            List <SelectListItem> zoneDropdown = new List <SelectListItem>();

            zoneDropdown = await PopulateZoneDropdownList();

            ViewBag.ZoneList = zoneDropdown;

            // Checks Name is not Null or Empty
            if (string.IsNullOrEmpty(artefact.Name))
            {
                ViewBag.ValidationName = "Name field is required.";
                return(View(artefact));
            }

            ArtefactDto newArtefact = new ArtefactDto();

            newArtefact.Id                 = artefact.Id;
            newArtefact.Name               = artefact.Name;
            newArtefact.Description        = artefact.Description;
            newArtefact.ModifiedDate       = artefact.ModifiedDate;
            newArtefact.Measurement_Height = artefact.Measurement_Height;
            newArtefact.Measurement_Length = artefact.Measurement_Length;
            newArtefact.Measurement_Width  = artefact.Measurement_Width;
            newArtefact.ArtefactCategory   = artefact.ArtefactCategory;
            newArtefact.XBound             = artefact.XBound;
            newArtefact.YBound             = artefact.YBound;

            if (ModelState.IsValid)
            {
                var request = new HTTPrequest();
                HttpPostedFileBase imgFile = Request.Files["ImageFile"];
                if (imgFile != null)
                {
                    artefact.Image = new byte[imgFile.ContentLength];
                    imgFile.InputStream.Read(artefact.Image, 0, imgFile.ContentLength);
                    string fileExtension = Path.GetExtension(imgFile.FileName);
                    artefact.ImageFileType = fileExtension;
                }
                artefact = await request.Post <ArtefactDto>("api/artefact", artefact);

                return(RedirectToAction("Index", new { recentAction = "Created", recentName = artefact.Name, recentId = artefact.Id }));
            }
            else
            {
                return(View(artefact));
            }
        }
        public async Task <ActionResult> Create(TourArtefactDto tourArtefact, int?tourId)
        {
            // Checks Order is not Negative or Empty
            if (tourArtefact.Order < 0 || tourArtefact.Order == null)
            {
                ViewBag.OrderValidation = "Order must be a positive integer.";
                return(View(tourArtefact));
            }
            bool tour_Selected = tourId.HasValue;
            //TOUR CATEGORY
            List <SelectListItem> tourDropdown = new List <SelectListItem>();

            if (tour_Selected)
            {
                tourDropdown = await PopulateTourDropdown(tour_Selected, tourId);
            }
            else
            {
                tourDropdown = await PopulateTourDropdown(tour_Selected, null);
            }
            ViewBag.TourList = tourDropdown;
            //ARTEFACT DROPDOWN
            List <SelectListItem> artefactDropdown = new List <SelectListItem>();

            artefactDropdown = await PopulateArtefactDropdown();

            ViewBag.ArtefactList = artefactDropdown;

            ViewBag.TourID = tourId.ToString();

            var     tourRequest = new HTTPrequest();
            TourDto tourCheck   = await tourRequest.Get <TourDto>("api/tour/" + tourArtefact.Tour.Id);

            TourArtefactDto newTourArtefact = new TourArtefactDto();

            if (tourCheck.Artefacts.Any(m => m.Order == tourArtefact.Order) && tourCheck.Artefacts.Any(m => m.Id == tourArtefact.Artefact.Id))
            {
                ViewBag.IndexAvail = false;
                return(View(newTourArtefact));
            }

            newTourArtefact.Artefact = await tourRequest.Get <ArtefactSimpleDto>("api/artefact/" + tourArtefact.Artefact.Id);

            TourSimpleDto tour = await tourRequest.Get <TourSimpleDto>("api/tour/" + tourArtefact.Tour.Id);

            newTourArtefact.Tour         = tour;
            newTourArtefact.Order        = tourArtefact.Order;
            newTourArtefact.CreatedDate  = DateTime.Now;
            newTourArtefact.ModifiedDate = DateTime.Now;
            var request = new HTTPrequest();
            await request.Post <TourArtefactDto>("api/tourArtefact", newTourArtefact);

            return(RedirectToAction("Index", "ToursArtefacts", new { tId = newTourArtefact.Tour.Id, recentAction = "Created", recentNameT = newTourArtefact.Tour.Name, recentIdT = newTourArtefact.Tour.Id, recentNameA = newTourArtefact.Artefact.Name, recentIdA = newTourArtefact.Artefact.Id }));
        }
        public async Task <ActionResult> Create(ArtefactInfoDto artefactInfo, HttpPostedFileBase ArtefactInfoFile)
        {
            ArtefactInfoDto newArtefactInfo = new ArtefactInfoDto();

            newArtefactInfo.Id               = artefactInfo.Id;
            newArtefactInfo.Artefact         = artefactInfo.Artefact;
            newArtefactInfo.ArtefactInfoType = artefactInfo.ArtefactInfoType;
            newArtefactInfo.CreatedDate      = DateTime.Now;
            newArtefactInfo.ModifiedDate     = DateTime.Now;
            newArtefactInfo.Description      = artefactInfo.Description;
            // need to parse apostrophes out
            newArtefactInfo.Content = artefactInfo.Content;

            // Checks Name is not Null or Empty
            if (artefactInfo.Artefact.Id.ToString() == null || string.IsNullOrEmpty(artefactInfo.Artefact.Id.ToString()))
            {
                ViewBag.ValidationName = "Artefact is required.";
                return(View(artefactInfo));
            }

            if (ModelState.IsValid)
            {
                var request = new HTTPrequest();
                //HttpPostedFileBase newFile = Request.Files["ArtefactInfoFile"];
                //HttpPostedFileBase newFile = ArtefactInfoFile;
                if (ArtefactInfoFile != null && ArtefactInfoFile.ContentLength > 0)
                {
                    artefactInfo.File = new byte[ArtefactInfoFile.ContentLength];
                    ArtefactInfoFile.InputStream.Read(artefactInfo.File, 0, ArtefactInfoFile.ContentLength);
                    string fileExtension = Path.GetExtension(ArtefactInfoFile.FileName);
                    artefactInfo.FileExtension = fileExtension;
                    if (ArtefactInfoFile == null)
                    {
                        throw new ArgumentException("file");
                    }
                }

                await request.Post <ArtefactInfoDto>("api/artefactInfo", artefactInfo);

                return(RedirectToAction("Index"));
            }

            return(View(artefactInfo));
        }
        public async Task <ActionResult> Create(TourDto tour, HttpPostedFileBase imageFile)
        {
            if (string.IsNullOrEmpty(tour.Name))
            {
                ViewBag.ValidationName = "Name field is required.";
                return(View(tour));
            }

            if (ModelState.IsValid)
            {
                tour.CreatedDate = DateTime.Now;
                var request = new HTTPrequest();
                tour = await request.Post <TourDto>("api/tour", tour);

                return(RedirectToAction("Index", new { recentAction = "Created", recentName = tour.Name, recentId = tour.Id }));
            }

            return(View());
        }
        public async Task <ActionResult> Create(ExhibitionDto exhibition, HttpPostedFileBase imageFile)
        {
            if (string.IsNullOrEmpty(exhibition.Name))
            {
                ViewBag.ValidationName = "Name field is required.";
                return(View(exhibition));
            }
            ExhibitionDto newExhibition = new ExhibitionDto();

            newExhibition.Id               = exhibition.Id;
            newExhibition.Name             = exhibition.Name;
            newExhibition.Description      = exhibition.Description;
            newExhibition.ModifiedDate     = exhibition.ModifiedDate;
            newExhibition.StartDate        = exhibition.StartDate;
            newExhibition.FinishDate       = exhibition.FinishDate;
            newExhibition.Price_Adult      = exhibition.Price_Adult;
            newExhibition.Price_Concession = exhibition.Price_Concession;
            newExhibition.Price_Child      = exhibition.Price_Child;

            if (ModelState.IsValid)
            {
                var request = new HTTPrequest();
                HttpPostedFileBase imgFile = Request.Files["ImageFile"];
                if (imgFile != null)
                {
                    exhibition.Image = new byte[imgFile.ContentLength];
                    imgFile.InputStream.Read(exhibition.Image, 0, imgFile.ContentLength);
                    string fileExtension = Path.GetExtension(imgFile.FileName);
                    //exhibition.ImageFileType = fileExtension;
                }
                exhibition = await request.Post <ExhibitionDto>("api/exhibition", exhibition);

                return(RedirectToAction("Index", new { recentAction = "Created", recentName = exhibition.Name, recentId = exhibition.Id }));
            }
            else
            {
                return(View());
            }
        }
Beispiel #9
0
        public async Task <ActionResult> PostApiExample(string name, string description)
        {
            try
            {
                var request = new HTTPrequest();

                ArtefactDto dto = new ArtefactDto()
                {
                    Name        = name,
                    Description = description,
                    //More properties here .....
                };

                dto = await request.Post <ArtefactDto>("api/artefact", dto);

                return(View(dto));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public async Task <ActionResult> Create(ZoneDto zone)
        {
            // Checks Name is not Null or Empty
            if (string.IsNullOrEmpty(zone.Name))
            {
                ViewBag.ValidationName = "Name field is required.";
                return(View(zone));
            }

            if (ModelState.IsValid && (zone.Name != null))
            {
                var request = new HTTPrequest();
                zone = await request.Post <ZoneDto>("api/zone", zone);

                return(RedirectToAction("Index", new { recentAction = "Created", recentName = zone.Name, recentId = zone.Id }));
            }
            else
            {
                var request = new HTTPrequest();
                ViewBag.Action = null;

                return(View());
            }
        }
Beispiel #11
0
        public async Task <ActionResult> Create(BeaconDto beacon)
        {
            // Checks Name is not Null or Empty
            if (string.IsNullOrEmpty(beacon.Name))
            {
                ViewBag.ValidationName = "Name field is required.";
                return(View(beacon));
            }

            if (ModelState.IsValid && (beacon.Name != null))
            {
                var request = new HTTPrequest();
                beacon = await request.Post <BeaconDto>("api/beacon", beacon);

                return(RedirectToAction("Index", new { recentAction = "Created", recentName = beacon.Name, recentId = beacon.Id }));
            }
            else
            {
                var request = new HTTPrequest();
                ViewBag.Action = null;

                return(View());
            }
        }