Пример #1
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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        public SaveResult Update(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 = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }

            return(result);
        }
Пример #4
0
        /// <summary>
        /// Sets the role.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <param name="roleType">Type of the role.</param>
        /// <returns></returns>
        public SaveResult SetRole(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 = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }

            return(result);
        }
Пример #5
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);
        }
Пример #6
0
        /// <summary>
        /// Adds the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Add(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 = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return(result);
        }
Пример #7
0
        /// <summary>
        /// Lockeds the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public SaveResult Locked(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 = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }

            return(result);
        }
Пример #8
0
        /// <summary>
        /// Updates the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Update(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 = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }

            return(result);
        }
Пример #9
0
        public SaveResult Update(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 = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }

            return(result);
        }
Пример #10
0
        /// <summary>
        /// Deletes the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Delete(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 = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }

            return(result);
        }
Пример #11
0
        /// <summary>
        /// Adds the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Add(RoleDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

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

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

                    context.Entry <Role>(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);
        }
Пример #12
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);
        }
Пример #13
0
        public SaveResult Add(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 = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return(result);
        }
Пример #14
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);
        }
Пример #15
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);
        }