示例#1
0
        /// <summary>
        /// Add a new category item
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public CategoryResponse AddCategory(Category request)
        {
            var result = new CategoryResponse
            {
                Meta = new Meta
                {
                    ResponseIdentifier = Guid.NewGuid(),
                    Date = DateTimeOffset.UtcNow.LocalDateTime
                }
            };

            try
            {
                context.Categories.Add(request);
                context.SaveChanges();
                result.Data = request;
            }
            catch (Exception e)
            {
                result.Meta.Messages = new List <string> {
                    e.Message
                };
            }



            return(result);
        }
示例#2
0
        public static void EnsurePopulated(IApplicationBuilder app)
        {
            CategoryDbContext context = app.ApplicationServices.GetRequiredService <CategoryDbContext>();

            context.Database.Migrate();

            if (!context.Categories.Any())
            {
                context.Categories.AddRange(
                    new Category {
                    CategoryId = Guid.NewGuid(), Name = "Memoria RAM", Active = true
                },
                    new Category {
                    CategoryId = Guid.NewGuid(), Name = "Discos Duros", Active = true
                },
                    new Category {
                    CategoryId = Guid.NewGuid(), Name = "Monitores", Active = true
                },
                    new Category {
                    CategoryId = Guid.NewGuid(), Name = "Accesorios", Active = true
                },
                    new Category {
                    CategoryId = Guid.NewGuid(), Name = "Limpieza", Active = true
                }
                    );
                context.SaveChanges();
            }
        }