コード例 #1
0
ファイル: ToolService.cs プロジェクト: ChaseAckeret/ToolChest
        //
        // Tool Catalogue Methods
        //

        public bool EditCatalogItem(int toolCatalogueItemId, ToolCatalogItemCreate toolCatalogItem)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .ToolCatalogItems
                    .Single(e => e.ToolCatalogItemID == toolCatalogueItemId);

                if (toolCatalogItem.LongDescription != null)
                {
                    entity.LongDescription = toolCatalogItem.LongDescription;
                }
                if (toolCatalogItem.Brand != null)
                {
                    entity.Brand = toolCatalogItem.Brand;
                }
                if (toolCatalogItem.PowerSource != null)
                {
                    entity.PowerSource = toolCatalogItem.PowerSource;
                }
                if (toolCatalogItem.Model != null)
                {
                    entity.Model = toolCatalogItem.Model;
                }

                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #2
0
        /// <summary>
        /// Change an existing ToolCatalogueItem object in the Database
        /// </summary>
        /// <param name="toolCatalogueItemId">Int to identify the existing ToolCatalogueItem</param>
        /// <param name="toolCatalogeItem">The new ToolCatalogueItem to replace the existing ToolCatalogueItem in the Database</param>
        /// <returns></returns>
        public IHttpActionResult Put(int toolCatalogueItemId, ToolCatalogItemCreate toolCatalogeItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateToolCatalogueItemService();

            if (!service.EditCatalogItem(toolCatalogueItemId, toolCatalogeItem))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
コード例 #3
0
ファイル: ToolService.cs プロジェクト: ChaseAckeret/ToolChest
        public bool CreateCatalogItem(ToolCatalogItemCreate model)
        {
            var entity =
                new ToolCatalogItem()
            {
                Catagory         = model.Catagory,
                ShortDescription = model.ShortDescription,
                LongDescription  = model.LongDescription,
                Brand            = model.Brand,
                PowerSource      = model.PowerSource,
                Model            = model.Model
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.ToolCatalogItems.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }