Ejemplo n.º 1
0
        public async Task <CosApiResponse> GetListProduct(RequestModelBase request)
        {
            var response = new CosApiResponse();

            try
            {
                using (var _db = new CosContext())
                {
                    GetListProductResponse result = new GetListProductResponse();

                    /* get product */
                    var query = _db.Products.Where(o => o.Status == (byte)Constants.EStatus.Actived);

                    result.ListProd = query.Select(o => new ProductDTO()
                    {
                        ID    = o.Id,
                        Name  = o.Name,
                        Price = (float)o.Price,
                    }).ToList();

                    /* response data  */
                    response.Data = result;

                    NSLog.Logger.Info("ResponseGetListProduct", response);
                }
            }
            catch (Exception ex) { NSLog.Logger.Error("ErrorGetListProduct", null, response, ex); }
            finally { /*_db.Refresh();*/ }
            return(response);
        }
Ejemplo n.º 2
0
        // Delete Order
        public async Task <CosApiResponse> DeleteOrder(RequestModelBase request)
        {
            var response = new CosApiResponse();

            try
            {
                using (var _db = new CosContext())
                {
                    /* delete */
                    var OrderDB = _db.Orders.Where(o => o.Id == request.ID && o.Status == (byte)Constants.EStatus.Actived).FirstOrDefault();
                    if (OrderDB != null)
                    {
                        OrderDB.Status = (byte)Constants.EStatus.Deleted;
                        /* Save change data */
                        if (_db.SaveChanges() > 0)
                        {
                            response.Success = true;
                        }
                        else
                        {
                            response.Message = "Unable to delete Order";
                        }
                    }
                    else
                    {
                        response.Message = "Unable to find Order";
                    }
                    NSLog.Logger.Info("Response Delete Order", response);
                }
            }
            catch (Exception ex) { NSLog.Logger.Error("Error Delete Order", null, response, ex); }
            finally { /*_db.Refresh();*/ }
            return(response);
        }
Ejemplo n.º 3
0
        // Get List Order
        public async Task <CosApiResponse> GetListOrder(RequestModelBase request)
        {
            var response = new CosApiResponse();

            try
            {
                using (var _db = new CosContext())
                {
                    GetListOrderResponse result = new GetListOrderResponse();

                    /* get oder */
                    var query = _db.Orders.Where(o => o.Status == (byte)Constants.EStatus.Actived);

                    result.ListOrder = query.Select(o => new OrderDTO()
                    {
                        Id         = o.Id,
                        CustomerId = o.CustomerId,
                        OrderNo    = o.OrderNo,
                        ReceiptNo  = o.ReceiptNo,
                        TotalBill  = o.TotalBill,
                        Discount   = o.Discount,
                    }).ToList();

                    /* response data  */
                    response.Data = result;

                    NSLog.Logger.Info("Response Get List Order", response);
                }
            }
            catch (Exception ex) { NSLog.Logger.Error("Error Get List Order", null, response, ex); }
            finally { /*_db.Refresh();*/ }
            return(response);
        }
Ejemplo n.º 4
0
        // Get Detail Category
        public async Task <CosApiResponse> GetDetailCategory(RequestModelBase request)
        {
            var response = new CosApiResponse();

            try
            {
                using (var _db = new CosContext())
                {
                    GetIDCategoryResponse result = new GetIDCategoryResponse();
                    var cateDB = _db.Categories.Where(x => x.Id == request.ID && x.Status == (byte)Constants.EStatus.Actived).FirstOrDefault();
                    if (cateDB != null)
                    {
                        var responseCate = new CategoryDTO()
                        {
                            Id       = cateDB.Id,
                            Name     = cateDB.Name,
                            ParentId = cateDB.ParentId,
                        };
                        result.Cate   = responseCate;
                        response.Data = result;
                    }
                    else
                    {
                        response.Message = "Unable to find category";
                        NSLog.Logger.Info("Response Get Detail Category", response);
                    }
                }
            }
            catch (Exception ex) { NSLog.Logger.Error("Error Get Detail Category", null, response, ex); }
            finally { }
            return(response);
        }
Ejemplo n.º 5
0
        //Get List Customer
        public async Task <CosApiResponse> GetListCustomer(RequestModelBase request)
        {
            var response = new CosApiResponse();

            try
            {
                using (var _db = new CosContext())
                {
                    GetListCustomerResponse result = new GetListCustomerResponse();

                    /* get Customer */
                    var query = _db.Customers.Where(o => true /* o.Status == Constants.EStatus.Actived*/);

                    result.ListCustomer = query.Select(o => new CustomersDTO()
                    {
                        Id      = o.Id,
                        Name    = o.Name,
                        Email   = o.Email,
                        Country = o.Country,
                        Phone   = o.Phone,
                        Active  = o.Active,
                        City    = o.City,
                    }).ToList();

                    /* response data  */
                    response.Data = result;

                    NSLog.Logger.Info("Response Get List customer", response);
                }
            }
            catch (Exception ex) { NSLog.Logger.Error("Error Get List customer", null, response, ex); }
            finally { /*_db.Refresh();*/ }
            return(response);
        }
Ejemplo n.º 6
0
        // Get List User
        public async Task <CosApiResponse> GetListUser(RequestModelBase request)
        {
            var response = new CosApiResponse();

            try
            {
                using (var _db = new CosContext())
                {
                    GetListUserResponse result = new GetListUserResponse();

                    /* get User */
                    var query = _db.Users.Where(o => o.Status == (byte)Constants.EStatus.Actived);

                    result.ListUser = query.Select(o => new UserDTO()
                    {
                        Id       = o.Id,
                        Name     = o.Name,
                        Email    = o.Email,
                        Password = o.Password,
                        Phone    = o.Phone,
                        Active   = o.Active,
                        RoleId   = o.RoleID,
                    }).ToList();

                    /* response data  */
                    response.Data = result;

                    NSLog.Logger.Info("Response Get List Users", response);
                }
            }
            catch (Exception ex) { NSLog.Logger.Error("Error Get List Users", null, response, ex); }
            finally { /*_db.Refresh();*/ }
            return(response);
        }
Ejemplo n.º 7
0
        public async Task <CosApiResponse> GetIDProduct(RequestModelBase request)
        {
            var response = new CosApiResponse();

            try
            {
                using (var _db = new CosContext())
                {
                    GetIDProductResponse result = new GetIDProductResponse();

                    /* get product */
                    var proDB = _db.Products.Where(o => o.Id == request.ID && o.Status == (byte)Constants.EStatus.Actived).FirstOrDefault();
                    if (proDB != null)
                    {
                        var responsePro = new ProductDTO()
                        {
                            ID    = proDB.Id,
                            Name  = proDB.Name,
                            Price = (float)proDB.Price,
                        };
                        result.Pro    = responsePro;
                        response.Data = result;
                    }
                    else
                    {
                        response.Message = "Unable to find product";
                    }

                    NSLog.Logger.Info("ResponseGetIDProduct", response);
                }
            }
            catch (Exception ex) { NSLog.Logger.Error("ErrorGetIDProduct", null, response, ex); }
            finally { /*_db.Refresh();*/ }
            return(response);
        }
Ejemplo n.º 8
0
        // Get List Role
        public async Task <CosApiResponse> GetListRole(RequestModelBase request)
        {
            var response = new CosApiResponse();

            try
            {
                using (var _db = new CosContext())
                {
                    GetListRoleResponse result = new GetListRoleResponse();

                    /* get Role */
                    var query = _db.Roles.Where(o => o.Status == (byte)Constants.EStatus.Actived);

                    result.ListRole = query.Select(o => new RoleDTO()
                    {
                        Id        = o.Id,
                        Name      = o.Name,
                        RoleLevel = o.RoleLevel,
                    }).ToList();

                    /* response data  */
                    response.Data = result;

                    NSLog.Logger.Info("Response Get List role", response);
                }
            }
            catch (Exception ex) { NSLog.Logger.Error("Error Get List role", null, response, ex); }
            finally { /*_db.Refresh();*/ }
            return(response);
        }
Ejemplo n.º 9
0
        // Get Detail Role
        public async Task <CosApiResponse> GetDetailRole(RequestModelBase request)
        {
            var response = new CosApiResponse();

            try
            {
                using (var _db = new CosContext())
                {
                    GetDetailRoleResponse result = new GetDetailRoleResponse();

                    /* get Role */
                    var RoleDB = _db.Roles.Where(o => o.Id == request.ID && o.Status == (byte)Constants.EStatus.Actived).FirstOrDefault();
                    if (RoleDB != null)
                    {
                        var responseRole = new RoleDTO()
                        {
                            Id        = RoleDB.Id,
                            Name      = RoleDB.Name,
                            RoleLevel = RoleDB.RoleLevel,
                        };
                        result.Role   = responseRole;
                        response.Data = result;
                    }
                    else
                    {
                        response.Message = "Unable to find role";
                    }

                    NSLog.Logger.Info("Response Get Detail role", response);
                }
            }
            catch (Exception ex) { NSLog.Logger.Error("Error Get Detail role", null, response, ex); }
            finally { /*_db.Refresh();*/ }
            return(response);
        }
Ejemplo n.º 10
0
        // Delete Category
        public async Task <CosApiResponse> DeleteCatgory(RequestModelBase request)
        {
            var response = new CosApiResponse();

            try
            {
                using (var _db = new CosContext())
                {
                    /* delete */
                    var cateDB = _db.Categories.Where(x => x.Id == request.ID && x.Status == (byte)Constants.EStatus.Actived).FirstOrDefault();
                    if (cateDB != null)
                    {
                        cateDB.Status = (byte)Constants.EStatus.Deleted;
                        if (_db.SaveChanges() > 0)
                        {
                            response.Success = true;
                        }
                        else
                        {
                            response.Message = "Unable to delete category";
                        }
                    }
                    else
                    {
                        response.Message = " Unable to find category";
                        NSLog.Logger.Info("Response Delete Category", response);
                    }
                }
            }
            catch (Exception ex) { NSLog.Logger.Error("Error Delete Category", null, response, ex); }
            finally { }
            return(response);
        }
Ejemplo n.º 11
0
        // Create Or Update Order
        public async Task <CosApiResponse> CreateUpdateOrder(OrderRequest request)
        {
            var response = new CosApiResponse();

            try
            {
                using (var _db = new CosContext())
                {
                    var Order = request.Order;
                    if (string.IsNullOrEmpty(Order.Id)) /* insert */
                    {
                        Order.Id = Guid.NewGuid().ToString();
                        var orderDB = new Order()
                        {
                            Id         = Order.Id,
                            CustomerId = Order.CustomerId,
                            ReceiptNo  = Order.ReceiptNo,
                            OrderNo    = Order.OrderNo,
                            TotalBill  = Order.TotalBill,
                            Discount   = Order.Discount,
                        };
                        _db.Orders.Add(orderDB);
                    }
                    else /* update */
                    {
                        var orderDB = _db.Orders.Where(o => o.Id == Order.Id && o.Status == (byte)Constants.EStatus.Actived).FirstOrDefault();
                        orderDB.CustomerId = Order.CustomerId;
                        orderDB.ReceiptNo  = Order.ReceiptNo;
                        orderDB.OrderNo    = Order.OrderNo;
                        orderDB.TotalBill  = Order.TotalBill;
                        orderDB.Discount   = Order.Discount;
                    }

                    /* save data */
                    if (_db.SaveChanges() > 0)
                    {
                        response.Success = true;
                    }
                    else
                    {
                        response.Message = "Unable to add new or update Order";
                    }
                    NSLog.Logger.Info("Response Create Update Order", response);
                }
            }
            catch (Exception ex) { NSLog.Logger.Error("Error Create Update Order", null, response, ex); }
            finally { /*_db.Refresh();*/ }
            return(response);
        }
Ejemplo n.º 12
0
        // Create Update Product
        public async Task <CosApiResponse> CreateUpdateProduct(CreateUpdateProductRequest request)
        {
            var response = new CosApiResponse();

            try
            {
                using (var _db = new CosContext())
                {
                    var pro = request.Pro;
                    if (string.IsNullOrEmpty(pro.ID)) /* insert */
                    {
                        pro.ID = Guid.NewGuid().ToString();
                        var proDB = new Product()
                        {
                            Id         = pro.ID,
                            Name       = pro.Name,
                            CategoryId = pro.CateID,
                            Price      = (decimal)pro.Price,
                            Status     = (byte)Constants.EStatus.Deleted,
                        };
                        _db.Products.Add(proDB);
                    }
                    else /* update */
                    {
                        var proDB = _db.Products.Where(o => o.Id == pro.ID && o.Status == (byte)Constants.EStatus.Actived).FirstOrDefault();
                        if (proDB != null)
                        {
                            proDB.Price      = (decimal)pro.Price;
                            proDB.Name       = pro.Name;
                            proDB.CategoryId = pro.CateID;
                        }
                    }

                    /* save data */
                    if (_db.SaveChanges() > 0)
                    {
                        response.Success = true;
                    }
                    else
                    {
                        response.Message = "Unable to add new or update product.";
                    }
                    NSLog.Logger.Info("ResponseCreateUpdateProduct", response);
                }
            }
            catch (Exception ex) { NSLog.Logger.Error("ErrorCreateUpdateProduct", null, response, ex); }
            finally { /*_db.Refresh();*/ }
            return(response);
        }
Ejemplo n.º 13
0
        // CreateUpdateCustomer
        public async Task <CosApiResponse> CreateUpdateCustomer(CustomerRequest request)
        {
            var response = new CosApiResponse();

            try
            {
                using (var _db = new CosContext())
                {
                    var customer = request.Customer;
                    if (string.IsNullOrEmpty(customer.Id)) /* insert */
                    {
                        customer.Id = Guid.NewGuid().ToString();
                        var customerDB = new Customer()
                        {
                            Id    = customer.Id,
                            Name  = customer.Name,
                            Email = customer.Email,
                            City  = customer.City,
                        };
                        _db.Customers.Add(customerDB);
                    }
                    else /* update */
                    {
                        var customerDB = _db.Customers.Where(o => o.Id == customer.Id && o.Status == (byte)Constants.EStatus.Actived).FirstOrDefault();
                        customerDB.Name  = customer.Name;
                        customerDB.Email = customer.Email;
                        customerDB.City  = customer.City;
                    }

                    /* save data */
                    if (_db.SaveChanges() > 0)
                    {
                        response.Success = true;
                    }
                    else
                    {
                        response.Message = "Unable to add new or update customer";
                    }
                    NSLog.Logger.Info("Response Create Update customer", response);
                }
            }
            catch (Exception ex) { NSLog.Logger.Error("Error Create Update customer", null, response, ex); }
            finally { /*_db.Refresh();*/ }
            return(response);
        }
Ejemplo n.º 14
0
        // Create Or Update Category
        public async Task <CosApiResponse> CreateUpdateCategory(CategoryRequest requests)
        {
            var response = new CosApiResponse();

            try
            {
                using (var _db = new CosContext())
                {
                    var Cate = requests.Category;
                    if (string.IsNullOrEmpty(Cate.Id))
                    {
                        Cate.Id = Guid.NewGuid().ToString();
                        var cateDB = new Category()
                        {
                            Id       = Cate.Id,
                            Name     = Cate.Name,
                            ParentId = Cate.ParentId,
                        };
                        _db.Categories.Add(cateDB);
                    }
                    else
                    {
                        var cateDB = _db.Categories.Where(x => x.Id == Cate.Id && x.Status == (byte)Constants.EStatus.Actived).FirstOrDefault();
                        cateDB.Name     = Cate.Name;
                        cateDB.ParentId = Cate.ParentId;
                    }
                    if (_db.SaveChanges() > 0)
                    {
                        response.Success = true;
                    }
                    else
                    {
                        response.Message = "Unable to add new or update category";
                        NSLog.Logger.Info("Response Create or Update Category", response);
                    }
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("Error Create Or Update Category", null, response, ex);
            }
            finally { }
            return(response);
        }
Ejemplo n.º 15
0
        // Create Or Update role
        public async Task <CosApiResponse> CreateUpdateRole(RoleRequest request)
        {
            var response = new CosApiResponse();

            try
            {
                using (var _db = new CosContext())
                {
                    var role = request.Role;
                    if (string.IsNullOrEmpty(role.Id)) /* insert */
                    {
                        role.Id = Guid.NewGuid().ToString();
                        var roleDB = new Role()
                        {
                            Id        = role.Id,
                            Name      = role.Name,
                            RoleLevel = role.RoleLevel,
                        };
                        _db.Roles.Add(roleDB);
                    }
                    else /* update */
                    {
                        var roleDB = _db.Roles.Where(o => o.Id == role.Id && o.Status == (byte)Constants.EStatus.Actived).FirstOrDefault();
                        roleDB.Name = role.Name;
                    }

                    /* save data */
                    if (_db.SaveChanges() > 0)
                    {
                        response.Success = true;
                    }
                    else
                    {
                        response.Message = "Unable to add new or update role";
                    }
                    NSLog.Logger.Info("Response Create Update role", response);
                }
            }
            catch (Exception ex) { NSLog.Logger.Error("Error Create Update role", null, response, ex); }
            finally { /*_db.Refresh();*/ }
            return(response);
        }
Ejemplo n.º 16
0
        // Get Detail Customer
        public async Task <CosApiResponse> GetDetailCustomer(RequestModelBase request)
        {
            var response = new CosApiResponse();

            try
            {
                using (var _db = new CosContext())
                {
                    GetDetailCustomerResponse result = new GetDetailCustomerResponse();

                    /* get Customer */
                    var customerDB = _db.Customers.Where(o => o.Id == request.ID && o.Status == (byte)Constants.EStatus.Actived).FirstOrDefault();
                    if (customerDB != null)
                    {
                        var responseUser = new CustomersDTO()
                        {
                            Id      = customerDB.Id,
                            Name    = customerDB.Name,
                            Email   = customerDB.Email,
                            Phone   = customerDB.Phone,
                            Active  = customerDB.Active,
                            City    = customerDB.City,
                            Country = customerDB.Country,
                        };
                        result.Customer = responseUser;
                        response.Data   = result;
                    }
                    else
                    {
                        response.Message = "Unable to find customer";
                    }

                    NSLog.Logger.Info("Response Get Detail customer", response);
                }
            }
            catch (Exception ex) { NSLog.Logger.Error("Error Get Detail customer", null, response, ex); }
            finally { /*_db.Refresh();*/ }
            return(response);
        }
Ejemplo n.º 17
0
        // Get Detail Order
        public async Task <CosApiResponse> GetDetailOrder(RequestModelBase request)
        {
            var response = new CosApiResponse();

            try
            {
                using (var _db = new CosContext())
                {
                    GetDetailOrderResponse result = new GetDetailOrderResponse();

                    /* get order */
                    var OrderDB = _db.Orders.Where(o => o.Id == request.ID && o.Status == (byte)Constants.EStatus.Actived).FirstOrDefault();
                    if (OrderDB != null)
                    {
                        var responseOrder = new OrderDTO()
                        {
                            Id         = OrderDB.Id,
                            CustomerId = OrderDB.CustomerId,
                            ReceiptNo  = OrderDB.ReceiptNo,
                            OrderNo    = OrderDB.OrderNo,
                            TotalBill  = OrderDB.TotalBill,
                            Discount   = OrderDB.Discount,
                        };
                        result.Order  = responseOrder;
                        response.Data = result;
                    }
                    else
                    {
                        response.Message = "Unable to find Order";
                    }

                    NSLog.Logger.Info("Response Get Detail Order", response);
                }
            }
            catch (Exception ex) { NSLog.Logger.Error("Error Get Detail Order", null, response, ex); }
            finally { /*_db.Refresh();*/ }
            return(response);
        }
Ejemplo n.º 18
0
        // Get List Category
        public async Task <CosApiResponse> GetListCategory(RequestModelBase request)
        {
            var response = new CosApiResponse();

            try
            {
                using (var _db = new CosContext())
                {
                    GetListCategoryResponse result = new GetListCategoryResponse();
                    var query = _db.Categories.Where(x => x.Status == (byte)Constants.EStatus.Actived);
                    result.ListCate = query.Select(x => new CategoryDTO()
                    {
                        Id       = x.Id,
                        Name     = x.Name,
                        ParentId = x.ParentId,
                    }).ToList();
                    response.Data = result;
                    NSLog.Logger.Info("Response Get List Category", response);
                }
            }
            catch (Exception ex) { NSLog.Logger.Error("Error Get List Category", null, response, ex); }
            finally { }
            return(response);
        }