コード例 #1
0
 public virtual JResponseEntity <T> Create(T entity)
 {
     if (ModelState.IsValid)
     {
         _context.Set <T>().Add(entity);
         _context.SaveChanges();
     }
     return(new JResponseEntity <T>());
 }
コード例 #2
0
        public Task <JResponseEntity <ProductsEntity> > CreateMultipleAsync(List <Products> Data)
        {
            JResponseEntity <ProductsEntity> RObj = new JResponseEntity <ProductsEntity>();

            try
            {
                _context.Products.AddRange(Data);
                _context.SaveChanges();
                RObj.Status = true;
            }
            catch (Exception e)
            {
                RObj.Message = e.InnerException != null ? e.InnerException.Message : e.Message;
            }
            return(Task.FromResult(RObj));
        }
コード例 #3
0
        public Task <JResponseEntity <UserEntity> > CreateAsync(Users Entity)
        {
            JResponseEntity <UserEntity> ResponseObj = new JResponseEntity <UserEntity>();

            try
            {
                _context.Users.Add(Entity);
                _context.SaveChanges();
                ResponseObj.Status = true;
                ResponseObj.Data   = new UserEntity()
                {
                    id         = Entity.Id,
                    username   = Entity.Username,
                    email      = Entity.Email,
                    first_name = Entity.FirstName,
                    last_name  = Entity.LastName
                };;
            }
            catch (Exception e)
            {
                ResponseObj.Message = e.InnerException != null ? e.InnerException.Message : e.Message;
            }
            return(Task.FromResult(ResponseObj));
        }