Example #1
0
 public async Task <Response> Delete(int id)
 {
     try
     {
         Company company = new Company();
         company.ID = id;
         using (KnowledgeTestDB dataBase = new KnowledgeTestDB())
         {
             dataBase.Entry(company).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
             await dataBase.SaveChangesAsync();
         }
         return(ResponseMessage.CreateSuccessResponse());
     }
     catch (Exception ex)
     {
         return(ResponseMessage.CreateErrorResponse(ex));
     }
 }
Example #2
0
        public async Task <Response> Update(Company company)
        {
            Response Response = Validate(company);

            if (Response.Success)
            {
                try
                {
                    using (KnowledgeTestDB dataBase = new KnowledgeTestDB())
                    {
                        dataBase.Entry(company).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                        await dataBase.SaveChangesAsync();
                    }
                    return(ResponseMessage.CreateSuccessResponse());
                }
                catch (Exception ex)
                {
                    return(ResponseMessage.CreateErrorResponse(ex));
                }
            }
            return(ResponseMessage.CreateErrorResponse(Response.Exception));
        }