public async Task <SaveResult> UpdateAsync(ProductDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    var product = context.Products.Single(x => x.Id == entity.ID && x.IsDeleted == false);

                    product.UnitPrice   = entity.UnitPrice;
                    product.ProductName = entity.ProductName;

                    context.Entry <Product>(product).State = System.Data.Entity.EntityState.Modified;
                    result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Sets the role asynchronous.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <param name="roleType">Type of the role.</param>
        /// <returns></returns>
        public async Task <SaveResult> SetRoleAsync(int id, RoleType roleType)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    var user = context.Users.Single(x => x.Id == id && x.IsDeleted == false);

                    user.RoleId     = (int)roleType;
                    user.LastUpdate = DateTime.Now;

                    context.Entry <User>(user).State = System.Data.Entity.EntityState.Modified;
                    result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }

            return(result);
        }
Exemple #3
0
        /// <summary>
        /// Adds the asynchronous.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public async Task <SaveResult> AddAsync(UserDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    User add = context.Users.Create();

                    add.Email         = entity.Email;
                    add.PasswordHash  = AppCipher.EncryptCipher(entity.PasswordHash);
                    add.RoleId        = entity.RoleId;
                    add.RegistedDate  = entity.RegistedDate;
                    add.Phone         = entity.Phone;
                    add.IsLocked      = entity.IsLocked;
                    add.Firstname     = entity.Firstname;
                    add.Lastname      = entity.Lastname;
                    add.LastLoginDate = entity.LastLoginDate;
                    add.IsDeleted     = entity.IsDeleted;
                    add.LastUpdatedBy = entity.LastUpdatedBy;
                    add.LastUpdate    = DateTime.Now;

                    context.Entry <User>(add).State = System.Data.Entity.EntityState.Added;
                    result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return(result);
        }
Exemple #4
0
        /// <summary>
        /// Lockeds the asynchronous.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public async Task <SaveResult> LockedAsync(int id)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    var assembly = context.Users.Single(x => x.Id == id && x.IsDeleted == false);

                    assembly.IsLocked   = true;
                    assembly.LastUpdate = DateTime.Now;

                    context.Entry <User>(assembly).State = System.Data.Entity.EntityState.Modified;
                    result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }

            return(result);
        }
Exemple #5
0
        /// <summary>
        /// Updates the asynchronous.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public async Task <SaveResult> UpdateAsync(UserDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    var update = context.Users.Single(x => x.Id == entity.ID && x.IsDeleted == false);

                    update.RoleId        = entity.RoleId;
                    update.Phone         = entity.Phone;
                    update.IsLocked      = entity.IsLocked;
                    update.Firstname     = entity.Firstname;
                    update.Lastname      = entity.Lastname;
                    update.IsDeleted     = entity.IsDeleted;
                    update.LastUpdatedBy = entity.LastUpdatedBy;
                    update.LastUpdate    = DateTime.Now;

                    context.Entry <User>(update).State = System.Data.Entity.EntityState.Modified;
                    result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }

            return(result);
        }
Exemple #6
0
        public async Task <SaveResult> UpdateAsync(CountryDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    var Country = context.Countries.Single(x => x.Id == entity.ID && x.IsDeleted == false);

                    Country.Name        = entity.Name;
                    Country.Description = entity.Description;

                    context.Entry <Country>(Country).State = System.Data.Entity.EntityState.Modified;
                    result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }

            return(result);
        }
Exemple #7
0
        /// <summary>
        /// Deletes the asynchronous.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public async Task <SaveResult> DeleteAsync(RoleDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    var role = context.Roles.Single(x => x.Id == entity.ID && x.IsDeleted == false);
                    role.IsDeleted     = true;
                    role.LastUpdate    = DateTime.Now;
                    role.LastUpdatedBy = entity.LastUpdatedBy;

                    context.Entry <Role>(role).State = System.Data.Entity.EntityState.Modified;
                    result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }

            return(result);
        }
Exemple #8
0
        /// <summary>
        /// Adds the asynchronous.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public async Task <SaveResult> AddAsync(RoleDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    Role add = context.Roles.Create();

                    add.Description   = entity.Description;
                    add.Name          = entity.Name;
                    add.IsDeleted     = false;
                    add.LastUpdatedBy = entity.LastUpdatedBy;
                    add.LastUpdate    = DateTime.Now;

                    context.Entry <Role>(add).State = System.Data.Entity.EntityState.Added;
                    result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return(result);
        }
        public async Task <SaveResult> AddAsync(ProductDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    Product add = context.Products.Create();

                    add.ProductName = entity.ProductName;
                    add.UnitPrice   = entity.UnitPrice;
                    context.Entry <Product>(add).State = System.Data.Entity.EntityState.Added;
                    result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return(result);
        }
Exemple #10
0
        public async Task <SaveResult> AddAsync(CountryDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    Country add = context.Countries.Create();

                    add.Description = entity.Description;
                    add.Name        = entity.Name;
                    context.Entry <Country>(add).State = System.Data.Entity.EntityState.Added;
                    result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return(result);
        }