Beispiel #1
0
        public async Task <ActionResult> Insert(Category obj)
        {
            var resource = new CategoryPostRep
            {
                Name        = obj.Name,
                Description = obj.Description
            };

            var response = await _proxy.PostAsync("categories", resource : resource);

            if (response.IsSuccessStatusCode)
            {
                CategoryViewModel model = new CategoryViewModel();
                var responseList        = await this._proxy.GetAsync("categories");

                dynamic responseContent = await responseList.Content.ReadAsAsync <Object>();

                model.Categories       = responseContent.Items.ToObject <List <Category> >();
                model.SelectedCategory = model.Categories.Find(o => o.Id == obj.Id);
                model.DisplayMode      = "ReadOnly";
                return(View("Index", model));
            }

            return(View("Index"));
        }
Beispiel #2
0
        public IHttpActionResult Update(string id, CategoryPostRep resource)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            try
            {
                var @event = new CategoryUpdateEvent
                {
                    Id          = Guid.Parse(id),
                    Name        = resource.Name,
                    Description = resource.Description
                };

                this._categoryService.Update(@event);

                return(this.CreatedAtRoute(CategoryResourceNames.Routes.GetById, new { id = @event.Id }, new { }));
            }
            catch (FormatException)
            {
                return(this.BadRequest());
            }
            catch (ObjectNotFoundException)
            {
                return(this.NotFound());
            }
            catch (Exception ex)
            {
                return(this.InternalServerError(ex));
            }
        }
Beispiel #3
0
        public IHttpActionResult Create(CategoryPostRep resource)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            try
            {
                var @event = new CategoryCreateEvent
                {
                    Name        = resource.Name,
                    Description = resource.Description
                };

                this._categoryService.Add(@event);

                return(this.CreatedAtRoute(CategoryResourceNames.Routes.GetById, new { id = @event.Id }, resource));
            }
            catch (Exception ex)
            {
                return(this.InternalServerError(ex));
            }
        }