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