Example #1
0
        public async Task <string> DeleteAsync(int?Id)
        {
            try
            {
                using (var context = new ALPHADataContext(this.options))
                {
                    var user = await context.Contacts.FirstOrDefaultAsync(x => x.Id == Id);

                    if (user == null)
                    {
                        return("No se encontrĂ³ el registro");
                    }
                    else
                    {
                        context.Remove(user);
                        await context.SaveChangesAsync();
                    }

                    return("Success");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Example #2
0
 public async Task <IEnumerable <Contact> > GetAllAsync()
 {
     try
     {
         using (var context = new ALPHADataContext(this.options))
         {
             return(await context.Contacts.ToListAsync());
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Example #3
0
 public async Task <Contact> GetAsync(int?Id)
 {
     try
     {
         using (var context = new ALPHADataContext(this.options))
         {
             return(await context.Contacts.FirstOrDefaultAsync(x => x.Id == Id));
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Example #4
0
 public async Task <User> getLogin(User model)
 {
     try
     {
         using (var context = new ALPHADataContext(this.options))
         {
             return(await context.Users.FirstOrDefaultAsync(x => x.Username == model.Username && x.Password == model.Password));
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Example #5
0
        public async Task <string> UpdateAsync(Contact model)
        {
            try
            {
                using (var context = new ALPHADataContext(this.options))
                {
                    context.Entry(model).State = EntityState.Modified;
                    await context.SaveChangesAsync();

                    return("Success");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Example #6
0
        public async Task <string> InsertAsync(Contact model)
        {
            using (var context = new ALPHADataContext(this.options))
            {
                try
                {
                    model.Date = new DateTime();
                    context.Contacts.Add(model);

                    await context.SaveChangesAsync();

                    return("Success");
                }
                catch (Exception ex)
                {
                    return(ex.Message);
                }
            }
        }