public ActionResult Create(string universityId)
        {
            if (!IsLoggedIn()) {
                return RedirectToLogin();
            }

            if (!UniversityHelper.IsFromUniversity(GetUserInformatonModel().Details, universityId)) {
                return SendToResultPage(UOMConstants.NOT_APART_OF_UNIVERSITY);
            }

            IDictionary<string, string> myItemTypes = DictionaryHelper.DictionaryWithSelect();

            try {
                myItemTypes = theMarketplaceService.CreateItemTypesDictionaryEntry();
            } catch (Exception myException) {
                LogError(myException, GET_ITEM_TYPES_ERROR);
                ViewData["Message"] = MessageHelper.ErrorMessage(GET_ITEM_TYPES_ERROR);
            }

            try {
                LoggedInWrapperModel<ItemViewModel> myLoggedIn = new LoggedInWrapperModel<ItemViewModel>(GetUserInformatonModel().Details);
                ItemViewModel myCreateItem = new ItemViewModel() {
                    UniversityId = universityId,
                    ItemTypes = new SelectList(myItemTypes, "Value", "Key")
                };
                myLoggedIn.Set(myCreateItem);
                return View("Create", myLoggedIn);
            } catch(Exception myException) {
                LogError(myException, ErrorKeys.ERROR_MESSAGE);
                return SendToErrorPage(ErrorKeys.ERROR_MESSAGE);
            }
        }
        public MarketplaceItem CreateItemListing(UserInformationModel<User> aCreatingUser, ItemViewModel anItemViewModel)
        {
            if (!ValidItem(anItemViewModel)) {
                return null;
            }

            string myImageName = string.Empty;

            if (anItemViewModel.Image != null) {
                try {
                    myImageName = AWSPhotoHelper.TakeImageAndResizeAndUpload(anItemViewModel.Image,
                        AWSHelper.GetClient(),
                        SiteConfiguration.MarketplacePhotosBucket(),
                        anItemViewModel.Title.GetHashCode().ToString(),
                        MarketplaceConstants.ITEM_MAX_SIZE);
                } catch (Exception myException) {
                    throw new PhotoException("Unable to upload the image.", myException);
                }
            }

            MarketplaceItem myItem = theMarketplaceRepository.AddItemToMarketplace(
                anItemViewModel.UniversityId,
                aCreatingUser.Details,
                anItemViewModel.ItemType,
                anItemViewModel.Title,
                anItemViewModel.Description,
                double.Parse(anItemViewModel.Price),
                myImageName,
                TimeZoneInfo.ConvertTimeToUtc(DateTime.Parse(anItemViewModel.ExpireListing)));

            return myItem;
        }
        public ActionResult Create(ItemViewModel anItemModel)
        {
            if (!IsLoggedIn()) {
                return RedirectToLogin();
            }

            UserInformationModel<User> myUserInformation = GetUserInformatonModel();

            try {
                MarketplaceItem myItem = theMarketplaceService.CreateItemListing(myUserInformation, anItemModel);

                if (myItem != null) {
                    TempData["Message"] += MessageHelper.SuccessMessage(ITEM_ADDED);
                    return RedirectToAction("Details", new { id = myItem.Id });
                }
            } catch(PhotoException myException) {
                LogError(myException, ITEM_IMAGE_UPLOAD_ERROR);
                TempData["Message"] += MessageHelper.ErrorMessage(ITEM_IMAGE_UPLOAD_ERROR);
            } catch (Exception myException) {
                LogError(myException, ErrorKeys.ERROR_MESSAGE);
                TempData["Message"] += MessageHelper.ErrorMessage(ErrorKeys.ERROR_MESSAGE);

            }

            theValidation.ForceModleStateExport();

            return RedirectToAction("Create");
        }
        public ActionResult Edit(ItemViewModel aViewModel)
        {
            if (!IsLoggedIn()) {
                return RedirectToLogin();
            }

            try {
                UserInformationModel<User> myUserInfo = GetUserInformatonModel();
                bool myResult = theMarketplaceService.EditItem(myUserInfo, aViewModel);

                if (myResult) {
                    TempData["Message"] += MessageHelper.SuccessMessage(ITEM_EDITED);
                    return RedirectToAction("Details", new { id = aViewModel.ItemId });
                }
            } catch (PhotoException anException) {
                LogError(anException, anException.Message);
                TempData["Message"] += MessageHelper.ErrorMessage(ITEM_PHOTO_UPLOAD_ERROR);
            } catch (CustomException anException) {
                LogError(anException, anException.Message);
                TempData["Message"] += MessageHelper.ErrorMessage(ITEM_PHOTO_UPLOAD_ERROR);
            } catch (Exception myException) {
                LogError(myException, ITEM_EDIT_ERROR);
                TempData["Message"] += MessageHelper.ErrorMessage(ITEM_EDIT_ERROR);
                theValidation.ForceModleStateExport();
            }

            return RedirectToAction("Edit", new { id = aViewModel.ItemId });
        }
        public ActionResult Edit(string universityId, int id)
        {
            if (!IsLoggedIn()) {
                return RedirectToLogin();
            }

            IDictionary<string, string> myItemTypes = DictionaryHelper.DictionaryWithSelect();

            try {
                myItemTypes = theMarketplaceService.CreateItemTypesDictionaryEntry();
            } catch (Exception myException) {
                LogError(myException, GET_ITEM_TYPES_ERROR);
                ViewData["Message"] = MessageHelper.ErrorMessage(GET_ITEM_TYPES_ERROR);
                return RedirectToAction("Details", new { id = id });
            }

            try {
                UserInformationModel<User> myUserInfo = GetUserInformatonModel();
                MarketplaceItem myItem = theMarketplaceService.GetItem(id);

                LoggedInWrapperModel<ItemViewModel> myLoggedIn = new LoggedInWrapperModel<ItemViewModel>(GetUserInformatonModel().Details);
                ItemViewModel myCreateItemModel = new ItemViewModel(myItem) {
                    UniversityId = universityId,
                    ItemTypes = new SelectList(myItemTypes, "Value", "Key", myItem.ItemTypeId)
                };
                myLoggedIn.Set(myCreateItemModel);

                return View("Edit", myLoggedIn);
            } catch (PermissionDenied myException) {
                TempData["Message"] += MessageHelper.WarningMessage(myException.Message);
            } catch (Exception myException) {
                LogError(myException, ErrorKeys.ERROR_MESSAGE);
                TempData["Message"] += MessageHelper.ErrorMessage(ITEM_GET_ERROR);
            }

            return RedirectToAction("Details", new { id = id });
        }
        public bool EditItem(UserInformationModel<User> aUserInfo, ItemViewModel anItemViewModel)
        {
            if (!ValidItem(anItemViewModel)) {
                return false;
            }

            MarketplaceItem myItem = GetItem(anItemViewModel.ItemId);
            myItem.Title = anItemViewModel.Title;
            myItem.Description = anItemViewModel.Description;
            myItem.Price = double.Parse(anItemViewModel.Price);
            myItem.ItemTypeId = anItemViewModel.ItemType;
            myItem.ExpireListing = TimeZoneInfo.ConvertTimeToUtc(DateTime.Parse(anItemViewModel.ExpireListing));

            theMarketplaceRepository.UpdateItem(myItem);

            if (anItemViewModel.Image != null) {
                string myOldItemPicture = myItem.ImageName;

                UpdateItemPhoto(anItemViewModel.ItemId.ToString(), anItemViewModel.Image, myItem);

                if (!string.IsNullOrEmpty(myOldItemPicture)) {
                    AWSPhotoHelper.PhysicallyDeletePhoto(AWSHelper.GetClient(), SiteConfiguration.TextbookPhotosBucket(), myOldItemPicture);
                }
            }

            return true;
        }
        private bool ValidItem(ItemViewModel anItemViewModel)
        {
            if (string.IsNullOrEmpty(anItemViewModel.UniversityId)) {
                theValidationDictionary.AddError("UniversityId", anItemViewModel.UniversityId, "A university must be present.");
            }

            if (string.IsNullOrEmpty(anItemViewModel.Title)) {
                theValidationDictionary.AddError("Title", anItemViewModel.Title, "You must give your item a title.");
            } else if (anItemViewModel.Title.Length > 100) {
                theValidationDictionary.AddError("Title", anItemViewModel.Title, "The title can only be 100 characters long.");
            }

            double myNum;
            if (!double.TryParse(anItemViewModel.Price, out myNum) || myNum < 0.01) {
                theValidationDictionary.AddError("Price", anItemViewModel.Price.ToString(), "The asking price must be above zero.");
            }

            if (!DropDownItemValidation.IsValid(anItemViewModel.ItemType)) {
                theValidationDictionary.AddError("ItemType", anItemViewModel.ItemType, "You must spcify an item type.");
            }

            if (anItemViewModel.Image != null && !PhotoValidation.IsValidImageFile(anItemViewModel.Image.FileName)) {
                theValidationDictionary.AddError("Image", anItemViewModel.Image.FileName, PhotoValidation.INVALID_IMAGE);
            }

            DateTime myStartTimeUtc = TimeZoneInfo.ConvertTimeToUtc(anItemViewModel.GetExpireDate());

            if (anItemViewModel.ExpireListing == null) {
                theValidationDictionary.AddError("ExpireListing", anItemViewModel.ExpireListing.ToString(), "Invalid date.");
            } else if (myStartTimeUtc <= DateTime.UtcNow) {
                theValidationDictionary.AddError("ExpireListing", anItemViewModel.ExpireListing.ToString(), "The expire date for the listing must be later than now.");
            }

            return theValidationDictionary.isValid;
        }