Example #1
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);
        }
        public SaveResult Add(OrderDetailDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    OrderDetail add = context.OrderDetails.Create();

                    add.OrderId   = entity.OrderId;
                    add.ProductId = entity.ProductId;
                    add.Quantity  = entity.Quantity;
                    add.UnitPrice = entity.UnitPrice;

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

            return(result);
        }
Example #3
0
        /// <summary>
        /// Gets all.
        /// </summary>
        /// <returns></returns>
        public IEnumerable <RoleDto> GetAll()
        {
            IEnumerable <RoleDto> results = null;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    results = (from item in context.Roles
                               where item.IsDeleted == false
                               select new RoleDto()
                    {
                        ID = item.Id,
                        Name = item.Name,
                        Description = item.Description,
                        IsDeleted = item.IsDeleted,
                        LastUpdatedBy = item.LastUpdatedBy,
                        LastUpdate = item.LastUpdate,
                    }).ToList();
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
            }
            return(results);
        }
Example #4
0
        public async Task <IEnumerable <CountryDto> > GetAllAsync()
        {
            List <CountryDto> results = null;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    results = await(from item in context.Countries
                                    where item.IsDeleted == false
                                    select new CountryDto()
                    {
                        ID          = item.Id,
                        Name        = item.Name,
                        Description = item.Description,
                    }).ToListAsync();
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                results = null;
            }
            return(results);
        }
Example #5
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);
        }
Example #6
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);
        }
Example #7
0
        public IEnumerable <ProductDto> GetAll()
        {
            List <ProductDto> results = null;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    results = (from item in context.Products
                               where item.IsDeleted == false
                               select new ProductDto()
                    {
                        ID = item.Id,
                        UnitPrice = item.UnitPrice,
                        ProductName = item.ProductName,
                    }).ToList();
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                results = null;
            }
            return(results);
        }
Example #8
0
        public CustomerDto AddCustomer(CustomerDto customer)
        {
            CustomerDto result = customer;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    Customer add = context.Customers.Create();

                    add.Name         = customer.Name;
                    add.Phone        = customer.Phone;
                    add.Email        = customer.Email;
                    add.CountryId    = customer.CountryId;
                    customer.Address = customer.Address;

                    context.Entry <Customer>(add).State = System.Data.Entity.EntityState.Added;
                    context.SaveChanges();

                    result.ID = add.Id;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = null;
            }

            return(result);
        }
Example #9
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);
        }
Example #10
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);
        }
Example #11
0
        /// <summary>
        /// Logins the asynchronous.
        /// </summary>
        /// <param name="email">The email.</param>
        /// <param name="password">The password.</param>
        /// <returns></returns>
        public async Task <UserDto> LoginAsync(string email, string password)
        {
            UserDto result = null;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    string passHash = AppCipher.EncryptCipher(password);
                    result = await(from item in context.Users
                                   where item.Email == email &&
                                   item.PasswordHash == passHash
                                   select new UserDto()
                    {
                        ID           = item.Id,
                        Email        = item.Email,
                        Firstname    = item.Firstname,
                        Lastname     = item.Lastname,
                        Phone        = item.Phone,
                        RegistedDate = item.RegistedDate,
                        RoleId       = item.RoleId,
                        Role         = new RoleDto()
                        {
                            ID = item.Role.Id, Name = item.Role.Name, Description = item.Role.Description
                        },
                    }).SingleAsync();
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = null;
            }
            return(result);
        }
Example #12
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);
        }
Example #13
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);
        }
Example #14
0
        public IEnumerable <OrderDetailDto> GetByOrder(int id)
        {
            IEnumerable <OrderDetailDto> results = null;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    results = (from item in context.OrderDetails
                               where item.IsDeleted == false && item.OrderId == id
                               select new OrderDetailDto
                    {
                        ID = item.Id,
                        Product = new ProductDto
                        {
                            ID = item.ProductId,
                            ProductName = item.Product.ProductName
                        },
                        Quantity = item.Quantity,
                        UnitPrice = item.UnitPrice,
                    }).ToList();
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                results = null;
            }
            return(results);
        }
Example #15
0
        /// <summary>
        /// Finds the asynchronous.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public async Task <RoleDto> SingleAsync(int id)
        {
            RoleDto result = null;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    result = await(from item in context.Roles
                                   where item.IsDeleted == false && item.Id == id
                                   select new RoleDto()
                    {
                        ID            = item.Id,
                        Name          = item.Name,
                        Description   = item.Description,
                        IsDeleted     = item.IsDeleted,
                        LastUpdatedBy = item.LastUpdatedBy,
                        LastUpdate    = item.LastUpdate,
                    }).SingleAsync();
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = null;
            }
            return(result);
        }
Example #16
0
        public OrderDto AddOrder(OrderDto order)
        {
            OrderDto result = order;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    Order add = context.Orders.Create();

                    add.CustomerId = order.CustomerId;
                    add.OrderDate  = order.OrderDate;
                    add.Status     = order.Status;

                    context.Entry <Order>(add).State = System.Data.Entity.EntityState.Added;
                    context.SaveChanges();

                    result.ID = add.Id;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = null;
            }

            return(result);
        }
Example #17
0
        public async Task <ProductDto> SingleAsync(int id)
        {
            ProductDto result = null;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    result = await(from item in context.Products
                                   where item.IsDeleted == false && item.Id == id
                                   select new ProductDto()
                    {
                        ID          = item.Id,
                        UnitPrice   = item.UnitPrice,
                        ProductName = item.ProductName,
                    }).SingleAsync();
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = null;
            }
            return(result);
        }
Example #18
0
        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);
        }
Example #19
0
        public decimal GetPrice(int id)
        {
            decimal?result = 0;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    result = (from item in context.Products
                              where item.IsDeleted == false && item.Id == id
                              select item.UnitPrice).FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = 0;
            }
            return(result.HasValue ? result.Value : 0);
        }
Example #20
0
        /// <summary>
        /// Gets all.
        /// </summary>
        /// <returns></returns>
        public IEnumerable <UserDto> GetAll()
        {
            IEnumerable <UserDto> results = null;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    results = (from item in context.Users
                               where item.IsDeleted == false
                               orderby item.Email
                               select new UserDto()
                    {
                        ID = item.Id,
                        Email = item.Email,
                        RegistedDate = item.RegistedDate,
                        Phone = item.Phone,
                        IsLocked = item.IsLocked,
                        Firstname = item.Firstname,
                        Lastname = item.Lastname,

                        RoleId = item.RoleId,
                        Role = new RoleDto()
                        {
                            ID = item.Role.Id, Name = item.Role.Name, Description = item.Role.Description
                        },
                        LastLoginDate = item.LastLoginDate,
                        IsDeleted = item.IsDeleted,
                        LastUpdatedBy = item.LastUpdatedBy,
                        LastUpdate = item.LastUpdate,
                    }).ToList();
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
            }
            return(results);
        }
Example #21
0
        public SaveResult Add(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 = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return(result);
        }
Example #22
0
        public SaveResult DeleteBy(int Id)
        {
            SaveResult result = SaveResult.FAILURE;

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

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

            return(result);
        }
Example #23
0
        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);
        }
Example #24
0
        public SaveResult UpdateStatus(int id, string status)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    var order = context.Orders.Single(x => x.Id == id && x.IsDeleted == false);
                    order.Status = status;

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

            return(result);
        }
Example #25
0
        public IEnumerable <OrderDto> GetAll()
        {
            List <OrderDto> results = null;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    results = (from item in context.Orders
                               where item.IsDeleted == false
                               orderby item.OrderDate
                               select new OrderDto()
                    {
                        ID = item.Id,
                        Status = item.Status,
                        OrderDate = item.OrderDate,
                        Customer = new CustomerDto
                        {
                            ID = item.Customer.Id,
                            Name = item.Customer.Name,
                            Address = item.Customer.Address,
                            Country = new CountryDto
                            {
                                ID = item.Customer.CountryId ?? 0,
                                Name = item.Customer.Country.Name,
                            },
                        },
                    }).ToList();
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                results = null;
            }
            return(results);
        }
Example #26
0
        /// <summary>
        /// Finds the asynchronous.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public async Task <UserDto> SingleAsync(int id)
        {
            UserDto result = null;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    result = await(from item in context.Users
                                   where item.IsDeleted == false && item.Id == id
                                   select new UserDto()
                    {
                        ID           = item.Id,
                        Email        = item.Email,
                        RegistedDate = item.RegistedDate,
                        Phone        = item.Phone,
                        IsLocked     = item.IsLocked,
                        Firstname    = item.Firstname,
                        Lastname     = item.Lastname,
                        RoleId       = item.RoleId,
                        Role         = new RoleDto()
                        {
                            ID = item.Role.Id, Name = item.Role.Name, Description = item.Role.Description
                        },
                        LastLoginDate = item.LastLoginDate,
                        IsDeleted     = item.IsDeleted,
                        LastUpdatedBy = item.LastUpdatedBy,
                        LastUpdate    = item.LastUpdate,
                    }).SingleAsync();
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
            }
            return(result);
        }
Example #27
0
        public decimal TotalOrder(int orderId)
        {
            decimal results = 0;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    results = (from item in context.OrderDetails
                               where item.IsDeleted == false && item.OrderId == orderId
                               select new
                    {
                        Price = item.UnitPrice,
                        Qty = item.Quantity,
                    }).Sum(x => (x.Price * x.Qty));
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                results = 0;
            }
            return(results);
        }
Example #28
0
        public async Task <OrderDto> SingleAsync(int id)
        {
            OrderDto result = null;

            try
            {
                using (OrderAppEntities context = new OrderAppEntities())
                {
                    result = await(from item in context.Orders
                                   where item.IsDeleted == false && item.Id == id
                                   select new OrderDto()
                    {
                        ID        = item.Id,
                        Status    = item.Status,
                        OrderDate = item.OrderDate,
                        Customer  = new CustomerDto
                        {
                            ID      = item.Customer.Id,
                            Name    = item.Customer.Name,
                            Address = item.Customer.Address,
                            Country = new CountryDto
                            {
                                ID   = item.Customer.CountryId ?? 0,
                                Name = item.Customer.Country.Name,
                            },
                        },
                    }).SingleAsync();
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = null;
            }
            return(result);
        }
Example #29
0
        /// <summary>
        /// Deletes the by.
        /// </summary>
        /// <param name="Id">The identifier.</param>
        /// <returns></returns>
        public SaveResult DeleteBy(int Id)
        {
            SaveResult result = SaveResult.FAILURE;

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

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

            return(result);
        }