public async Task <ActionResult> Create(MapEntity model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }

            model.PartitionKey = MapEntity.MainKey;
            model.RowKey       = ShortGuid.NewGuid().Value;

            try
            {
                // upload image to blob storage.
                model.ImageAddress = await UploadImageToStorage(model.RowKey, model.ImageAddress);

                await TableStorage.Insert(model);
            }
            catch (StorageException error)
            {
                Task.Run(() => RavenClient.CaptureException(error));

                ViewBag.Alerts = new List <AlertModel> {
                    new AlertModel(AlertType.Danger, error.Message)
                };

                return(this.View(model));
            }

            this.TempData["Alerts"] = AlertModel.CreateSingle(AlertType.Success, string.Format("{0} by {1} was created.", model.Title, model.Author));

            this.TempData["Highlight"] = new HighlightModel(AlertType.Success, model.PartitionKey, model.RowKey);

            return(this.RedirectToAction("Index"));
        }
示例#2
0
        public async Task <ActionResult> Edit(string row, MapEntity model)
        {
            if (string.IsNullOrEmpty(model.FeaturedDate))
            {
                ModelState.AddModelError("FeaturedDate", "A featured date is required.");
            }

            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }

            try
            {
                await TableStorage.Replace(model);
            }
            catch (StorageException error)
            {
                Task.Run(() => RavenClient.CaptureException(error));

                return(this.AzureStorageErrorResponse(row, MapEntity.FeaturedKey, error));
            }

            string alertMessage = string.Format("The featured map for {0} was updated.", model.FeaturedDate);

            this.TempData["Alerts"] = AlertModel.CreateSingle(AlertType.Success, alertMessage);

            this.TempData["Highlight"] = new HighlightModel(AlertType.Info, model.PartitionKey, model.RowKey);

            return(this.RedirectToAction("Index"));
        }
        /// <summary>
        /// Returns the view with an updated model in the event of a storage error.
        /// </summary>
        /// <param name="row">The maps row key.</param>
        /// <param name="partition">The maps partition.</param>
        /// <param name="error">The storage error.</param>
        /// <returns>An updated view.</returns>
        protected ActionResult AzureStorageErrorResponse(string row, string partition, StorageException error)
        {
            Guard.NotNullOrEmpty(() => row);
            Guard.NotNullOrEmpty(() => partition);
            Guard.NotNull(() => error);

            ViewBag.Alerts = AlertModel.CreateSingle(AlertType.Danger, error.Message);

            var entityTask = TableStorage.Get(partition, row);

            Task.WaitAll(entityTask);

            return(this.View(entityTask.Result));
        }
        public async Task <ActionResult> Delete(string row, MapEntity model)
        {
            MapEntity entity = await TableStorage.Get(MapEntity.MainKey, row);

            try
            {
                await TableStorage.Delete(entity);
            }
            catch (StorageException error)
            {
                Task.Run(() => RavenClient.CaptureException(error));

                return(this.AzureStorageErrorResponse(row, MapEntity.MainKey, error));
            }

            this.TempData["Alerts"] = AlertModel.CreateSingle(AlertType.Info, string.Format("{0} by {1} was deleted.", entity.Title, entity.Author));

            return(this.RedirectToAction("Index"));
        }
示例#5
0
        public async Task <ActionResult> Create(MapEntity model)
        {
            if (string.IsNullOrEmpty(model.FeaturedDate))
            {
                ModelState.AddModelError("FeaturedDate", "A featured date is required.");
            }

            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }

            model.PartitionKey = MapEntity.FeaturedKey;
            model.RowKey       = ShortGuid.NewGuid().Value;

            try
            {
                await TableStorage.Insert(model);
            }
            catch (StorageException error)
            {
                Task.Run(() => RavenClient.CaptureException(error));

                ViewBag.Alerts = new List <AlertModel> {
                    new AlertModel(AlertType.Danger, error.Message)
                };

                return(this.View(model));
            }

            string alertMessage = string.Format("{0} by {1} for {2} was created.", model.Title, model.Author, model.FeaturedDate);

            this.TempData["Alerts"] = AlertModel.CreateSingle(AlertType.Success, alertMessage);

            this.TempData["Highlight"] = new HighlightModel(AlertType.Success, model.PartitionKey, model.RowKey);

            return(this.RedirectToAction("Index"));
        }
        public async Task <ActionResult> Edit(string row, MapEntity model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }

            try
            {
                await TableStorage.Replace(model);
            }
            catch (StorageException error)
            {
                Task.Run(() => RavenClient.CaptureException(error));

                return(this.AzureStorageErrorResponse(row, MapEntity.MainKey, error));
            }

            this.TempData["Alerts"] = AlertModel.CreateSingle(AlertType.Success, string.Format("{0} by {1} was updated.", model.Title, model.Author));

            this.TempData["Highlight"] = new HighlightModel(AlertType.Info, model.PartitionKey, model.RowKey);

            return(this.RedirectToAction("Index"));
        }