Exemple #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);
            }
        }
Exemple #2
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);
            }
        }
Exemple #3
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);
                }
            }
        }