Ejemplo n.º 1
0
        // Update Personal Details
        public static async Task <bool> UpdatePersonalDetails(PersonalDetailViewModel model)
        {
            try
            {
                Errors.Clear();
                using (var db = new WebApiProjectDbContext())
                    using (var repo = new EntityFrameworkRepository <WebApiProjectDbContext>(db))
                    {
                        var entity = await db.PersonalDetails.FindAsync(model.Id);

                        entity.FirstName   = model.FirstName;
                        entity.LastName    = model.LastName;
                        entity.Age         = model.Age;
                        entity.BirthDate   = model.BirthDate;
                        entity.Email       = model.Email;
                        entity.PhoneNumber = model.PhoneNumber;

                        repo.Update <PersonalDetail>(entity);
                        return(await db.SaveChangesAsync() == 0 ? false : true);
                    }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);

                //Add Error message
                Errors.Add("There was an error trying to send the information to the database");
                return(false);
            }
        }
Ejemplo n.º 2
0
        public async Task <T> FindById(string id)
        {
            try
            {
                _errors.Clear();
                _errorDetail.Clear();
                using (var db = new WebApiProjectDbContext())
                    using (var repo = new EntityFrameworkRepository <WebApiProjectDbContext>(db))
                    {
                        var temp = await repo.GetByIdAsync <T>(id);

                        if (temp.IsDeleted == true)
                        {
                            return(null);
                        }
                        return(temp);
                    }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);

                //Add Error message
                _errors.Add("There was an error trying to reading data from database");
                _errorDetail.Add(e.Message);
                _errorDetail.Add(e.InnerException.Message);
                return(null);
            }
        }
Ejemplo n.º 3
0
        // Create Personal Details
        public static async Task <PersonalDetail> CreatePersonalDetails(PersonalDetailViewModel model)
        {
            try
            {
                using (var db = new WebApiProjectDbContext())
                    using (var repo = new EntityFrameworkRepository <WebApiProjectDbContext>(db))
                    {
                        var entity = new PersonalDetail()
                        {
                            Email       = model.Email,
                            FirstName   = model.FirstName,
                            LastName    = model.LastName,
                            BirthDate   = model.BirthDate,
                            PhoneNumber = model.PhoneNumber,
                            Age         = model.Age,
                        };

                        repo.Create <PersonalDetail>(entity);
                        var result = await db.SaveChangesAsync() == 0 ? null : entity;

                        return(result);
                    }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);
                return(null);
            }
        }
Ejemplo n.º 4
0
        // List all Personal Details
        public static async Task <List <PersonalDetail> > ListAllPersonalDetails()
        {
            try
            {
                using (var db = new WebApiProjectDbContext())
                    using (var repo = new EntityFrameworkRepository <WebApiProjectDbContext>(db))
                    {
                        var personalDetails = await db.PersonalDetails.ToListAsync();

                        personalDetails = personalDetails.Where(_ => _.IsDeleted == false).ToList();
                        return(personalDetails);
                    }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);
                return(null);
            }
        }
Ejemplo n.º 5
0
        // Delete Personal Details
        public static async Task <bool> DeletePersonalDetails(Guid Id)
        {
            try
            {
                Errors.Clear();
                using (var db = new WebApiProjectDbContext())
                    using (var repo = new EntityFrameworkRepository <WebApiProjectDbContext>(db))
                    {
                        var entity = await db.PersonalDetails.FindAsync(Id);

                        repo.Delete <PersonalDetail>(entity);
                        return(await db.SaveChangesAsync() == 0 ? false : true);
                    }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);
                return(false);
            }
        }
Ejemplo n.º 6
0
        public async Task <bool> Add(T entity)
        {
            try
            {
                _errors.Clear();
                _errorDetail.Clear();
                using (var db = new WebApiProjectDbContext())
                    using (var repo = new EntityFrameworkRepository <WebApiProjectDbContext>(db))
                    {
                        repo.Create <T>(entity);
                        return(await db.SaveChangesAsync() == 0 ? false : true);
                    }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);

                //Add Error message
                _errors.Add("There was an error trying to send the information to the database ");
                return(false);
            }
        }
Ejemplo n.º 7
0
        public async Task <IEnumerable <T> > List()
        {
            try
            {
                Errors.Clear();
                using (var db = new WebApiProjectDbContext())
                    using (var repo = new EntityFrameworkRepository <WebApiProjectDbContext>(db))
                    {
                        return(await repo.GetAllAsync <T>());
                    }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);

                //Add Error message
                //Errors.Add("There was an error trying to reading data from database ");
                _errors.Add("There was an error trying to reading data from database ");

                return(null);
            }
        }
Ejemplo n.º 8
0
        // Find Personal Details
        public static async Task <PersonalDetail> FindPersonalDetailsById(Guid id)
        {
            try
            {
                Errors.Clear();
                using (var db = new WebApiProjectDbContext())
                    using (var repo = new EntityFrameworkRepository <WebApiProjectDbContext>(db))
                    {
                        var profiles = await db.PersonalDetails.ToListAsync();

                        var profile = profiles.Where(_ => _.Id == id).FirstOrDefault();
                        return(profile);
                    }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);

                //Add Error message
                Errors.Add("There was an error trying to reading data from database");
                return(null);
            }
        }
Ejemplo n.º 9
0
        public async Task Delete(T entity)
        {
            try
            {
                _errors.Clear();
                _errorDetail.Clear();

                using (var db = new WebApiProjectDbContext())
                    using (var repo = new EntityFrameworkRepository <WebApiProjectDbContext>(db))
                    {
                        repo.Delete <T>(entity);
                        await db.SaveChangesAsync();
                    }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);

                //Add Error message
                _errors.Add("There was an error trying to send the information to the database ");
                _errorDetail.Add(e.Message);
                _errorDetail.Add(e.InnerException.Message);
            }
        }