Esempio n. 1
0
        public InfrastructureLayer.Models.Category Add(InfrastructureLayer.Models.Category item)
        {
            var      _ctx      = Ctx;
            Category addedItem = _ctx.Categories.Add(item.ToEF());

            _ctx.SaveChanges();
            return(addedItem.ToDto());
        }
Esempio n. 2
0
 public static Category ToEF(this InfrastructureLayer.Models.Category @this)
 {
     return(new Category
     {
         Id = @this.Id ?? default(int),
         Name = @this.Name,
         ImageUrlRelative = @this.ImageUrlRelative
     });
 }
Esempio n. 3
0
        public InfrastructureLayer.Models.Category Update(InfrastructureLayer.Models.Category item)
        {
            var _ctx = Ctx;

            if (item.Id == null)
            {
                throw new NullReferenceException("Category Id can not be null");
            }
            Category tobeUpdate = _ctx.Categories.Find(item.Id.Value);

            if (tobeUpdate == null)
            {
                return(null);
            }
            tobeUpdate.Name             = item.Name;
            tobeUpdate.ImageUrlRelative = item.ImageUrlRelative;
            _ctx.SaveChanges();
            return(tobeUpdate.ToDto());
        }