public List <OrderDTO> GetOrdersByClient(int userId)
        {
            using (var context = new PizzeriaMasterpieceEntities())
            {
                var result = context.Orders.Where(p => p.UserId == userId)
                             .Select(q => new OrderDTO
                {
                    OrderId          = q.OrderId,
                    OrderNo          = q.OrderNo,
                    Address          = q.Address,
                    Date             = q.Date,
                    Remark           = q.Remark,
                    DocumentTypeId   = q.DocumentTypeId,
                    DocumentTypeName = q.DocumentType.Name,
                    OrderStatusId    = q.OrderStatusId,
                    OrderStatusName  = q.OrderStatu.Name,
                    OrderDetails     = q.OrderDetails.Select(r => new OrderDetailDTO {
                        OrderDetailId = r.OrderDetailId,
                        ProductId     = r.ProductId.Value,
                        ProductName   = r.Product.Name,
                        Price         = r.Price,
                        Quantity      = r.Quantity,
                        TotalPrice    = r.TotalPrice
                    }).ToList()
                }).ToList();

                return(result);
            }
        }
Esempio n. 2
0
 public int UpdateSupply(SupplyDTO supply)
 {
     using (var context = new PizzeriaMasterpieceEntities())
     {
         var currentSupply = context.Supplies.Find(supply.SupplyId);
         if (!string.IsNullOrWhiteSpace(supply.Name))
         {
             currentSupply.Name = supply.Name;
         }
         if (!string.IsNullOrWhiteSpace(supply.Code))
         {
             currentSupply.Code = supply.Code;
         }
         if (!string.IsNullOrWhiteSpace(supply.Description))
         {
             currentSupply.Description = supply.Description;
         }
         if (supply.Quantity != null)
         {
             currentSupply.Quantity = supply.Quantity;
         }
         if (supply.IsActive != null)
         {
             currentSupply.IsActive = supply.IsActive;
         }
         context.SaveChanges();
         return(currentSupply.SupplyId);
     }
 }
 public int UpdateCompany(CompanyDTO company)
 {
     using (var context = new PizzeriaMasterpieceEntities())
     {
         var currentCompany = context.Companies.Find(company.CompanyId);
         if (!string.IsNullOrWhiteSpace(company.Name))
         {
             currentCompany.Name = company.Name;
         }
         if (!string.IsNullOrWhiteSpace(company.RUC))
         {
             currentCompany.Name = company.RUC;
         }
         if (!string.IsNullOrWhiteSpace(company.Address))
         {
             currentCompany.Name = company.Address;
         }
         if (!string.IsNullOrWhiteSpace(company.PhoneNumber))
         {
             currentCompany.Name = company.PhoneNumber;
         }
         context.SaveChanges();
         return(currentCompany.CompanyId);
     }
 }
Esempio n. 4
0
 public int UpdateProduct(ProductDTO product)
 {
     using (var context = new PizzeriaMasterpieceEntities())
     {
         var currentProduct = context.Products.Find(product.ProductId);
         if (!string.IsNullOrWhiteSpace(product.Description))
         {
             currentProduct.Description = product.Description;
         }
         if (product.Price != null)
         {
             currentProduct.Price = product.Price.Value;
         }
         if (!string.IsNullOrWhiteSpace(product.ImagePath))
         {
             currentProduct.ImagePath = product.ImagePath;
         }
         if (product.IsActive != null)
         {
             currentProduct.IsActive = product.IsActive;
         }
         context.SaveChanges();
         return(currentProduct.ProductId);
     }
 }
        public UserDTO LoginUser(UserLoginDTO user)
        {
            var password = HashPassword(user.Password);

            using (var context = new PizzeriaMasterpieceEntities())
            {
                var result = context.Users
                             .Where(p => p.Email == user.Email && p.Password == password && p.IsActive == 1)
                             .Select(q => new UserDTO
                {
                    UserId      = q.UserId,
                    DocumentNo  = q.DocumentNo,
                    FirstName   = q.FirstName,
                    LastName    = q.LastName,
                    Email       = q.Email,
                    Address     = q.Address,
                    PhoneNumber = q.PhoneNumber,
                    RoleId      = q.RoleId,
                    RoleName    = q.Role.Name,
                    IsActive    = q.IsActive
                })
                             .FirstOrDefault();
                return(result);
            }
        }
 public int UpdateOrderStatus(OrderStatusDTO order)
 {
     using (var context = new PizzeriaMasterpieceEntities())
     {
         var currentOrder = context.Orders.Find(order.OrderId);
         currentOrder.OrderStatusId = order.OrderStatusId;
         context.SaveChanges();
         return(currentOrder.OrderId);
     }
 }
 public List <SupplyDTO> GetSuppliesByProduct(int productId)
 {
     using (var context = new PizzeriaMasterpieceEntities()) {
         var result = context.ProductSupplies.Where(p => p.ProductId == productId)
                      .Select(r => new SupplyDTO
         {
             SupplyId = r.SupplyId,
             Quantity = r.Quantity
         }).ToList();
         return(result);
     }
 }
Esempio n. 8
0
        public List <ControlBaseDTO> GetSizes()
        {
            using (var context = new PizzeriaMasterpieceEntities())
            {
                var result = context.Sizes
                             .Select(q => new ControlBaseDTO
                {
                    Id   = q.SizeId,
                    Code = q.Code,
                    Name = q.Name,
                }).ToList();

                return(result);
            }
        }
        public List <OrderWorkerDTO> GetOrdersByCriteria(OrderSearchCriteriaDTO criteria)
        {
            using (var context = new PizzeriaMasterpieceEntities())
            {
                var query = context.Orders.Where(p => p.UserId == criteria.UserId || criteria.UserId == null);
                query = query.Where(p => p.OrderStatusId == criteria.OrderStatusId || criteria.OrderStatusId == null);
                query = query.Where(p => p.Date >= criteria.StartDate || criteria.StartDate == null);
                query = query.Where(p => p.Date <= criteria.EndDate || criteria.EndDate == null);

                var result = query.Select(q => new OrderWorkerDTO
                {
                    OrderId          = q.OrderId,
                    OrderNo          = q.OrderNo,
                    Address          = q.Address,
                    Date             = q.Date,
                    Remark           = q.Remark,
                    DocumentTypeId   = q.DocumentTypeId,
                    DocumentTypeName = q.DocumentType.Name,
                    OrderStatusId    = q.OrderStatusId,
                    OrderStatusName  = q.OrderStatu.Name,
                    DocumentNo       = q.User.DocumentNo,
                    Email            = q.User.Email,
                    FirstName        = q.User.FirstName,
                    LastName         = q.User.LastName,
                    PhoneNumber      = q.User.PhoneNumber,
                    OrderDetails     = q.OrderDetails.Select(r => new OrderDetailDTO
                    {
                        OrderDetailId = r.OrderDetailId,
                        ProductId     = r.ProductId.Value,
                        ProductName   = r.Product.Name,
                        Price         = r.Price,
                        Quantity      = r.Quantity,
                        TotalPrice    = r.TotalPrice,
                        Supplies      = r.Product.ProductSupplies.Select(p => new SupplyDTO
                        {
                            SupplyId    = p.Supply.SupplyId,
                            Code        = p.Supply.Code,
                            Description = p.Supply.Description,
                            IsActive    = p.Supply.IsActive,
                            Name        = p.Supply.Name,
                            Quantity    = p.Supply.Quantity
                        }).ToList()
                    }).ToList()
                }).OrderByDescending(q => q.Date).ToList();

                return(result);
            }
        }
Esempio n. 10
0
 public List <SupplyDTO> GetSupplies()
 {
     using (var context = new PizzeriaMasterpieceEntities())
     {
         var result = context.Supplies.Where(t => t.IsActive == 1)
                      .Select(s => new SupplyDTO
         {
             SupplyId    = s.SupplyId,
             Code        = s.Code,
             Description = s.Description,
             Name        = s.Name,
             Quantity    = s.Quantity
         }).ToList();
         return(result);
     }
 }
 public int UpdateUser(UserRegistrationDTO user)
 {
     using (var context = new PizzeriaMasterpieceEntities())
     {
         var currentUser = context.Users.Find(user.UserId);
         currentUser.FirstName   = user.FirstName;
         currentUser.LastName    = user.LastName;
         currentUser.Address     = user.Address;
         currentUser.PhoneNumber = user.PhoneNumber;
         if (!string.IsNullOrWhiteSpace(user.Password))
         {
             currentUser.Password = HashPassword(user.Password);
         }
         context.SaveChanges();
         return(currentUser.UserId);
     }
 }
        public CompanyDTO GetCompany(int companyId)
        {
            using (var context = new PizzeriaMasterpieceEntities())
            {
                var result = context.Companies.Where(p => p.CompanyId == companyId)
                             .Select(q => new CompanyDTO
                {
                    CompanyId   = q.CompanyId,
                    Name        = q.Name,
                    RUC         = q.RUC,
                    Address     = q.Address,
                    PhoneNumber = q.PhoneNumber,
                }).FirstOrDefault();

                return(result);
            }
        }
Esempio n. 13
0
 public SupplyDTO InsertSupply(SupplyDTO supply)
 {
     using (var context = new PizzeriaMasterpieceEntities())
     {
         var newSupply = new Supply
         {
             SupplyId    = -1,
             Code        = supply.Code,
             Name        = supply.Name,
             Description = supply.Description,
             Quantity    = supply.Quantity,
             IsActive    = 1,
         };
         context.Supplies.Add(newSupply);
         context.SaveChanges();
         return(GetSupplyById(newSupply.SupplyId));
     }
 }
        public List <CompanyDTO> GetCompanyList()
        {
            using (var context = new PizzeriaMasterpieceEntities())
            {
                var result = context.Companies
                             .Select(q => new CompanyDTO
                {
                    CompanyId   = q.CompanyId,
                    Name        = q.Name,
                    RUC         = q.RUC,
                    Address     = q.Address,
                    PhoneNumber = q.PhoneNumber
                })
                             .ToList();

                return(result);
            }
        }
Esempio n. 15
0
        public SupplyDTO GetSupplyById(int supplyId)
        {
            using (var context = new PizzeriaMasterpieceEntities())
            {
                var result = context.Supplies.Where(w => w.SupplyId == supplyId)
                             .Select(a => new SupplyDTO
                {
                    SupplyId    = a.SupplyId,
                    Code        = a.Code,
                    Description = a.Description,
                    Name        = a.Name,
                    Quantity    = a.Quantity,
                    IsActive    = a.IsActive
                }).FirstOrDefault();

                return(result);
            }
        }
        public int InsertCompany(CompanyDTO company)
        {
            using (var context = new PizzeriaMasterpieceEntities())
            {
                var newCompany = new Company
                {
                    CompanyId   = -1,
                    Name        = company.Name,
                    RUC         = company.RUC,
                    Address     = company.Address,
                    PhoneNumber = company.PhoneNumber,
                };

                context.Companies.Add(newCompany);
                context.SaveChanges();

                return(newCompany.CompanyId);
            }
        }
 public List <SupplyProductDTO> GetAllProductBySupply(int supplyId)
 {
     using (var context = new PizzeriaMasterpieceEntities()) {
         var result = context.Supplies.Where(p => p.SupplyId == supplyId)
                      .Select(q => new SupplyProductDTO
         {
             SupplyId       = q.SupplyId,
             Code           = q.Code,
             Name           = q.Name,
             Description    = q.Description,
             Quantity       = q.Quantity,
             IsActive       = q.IsActive,
             ProductDetails = q.ProductSupplies.Select(r => new SupplyProductDetailDTO {
                 ProductId = r.ProductId,
                 Quantity  = r.Quantity
             }).ToList()
         }).ToList();
         return(result);
     }
 }
Esempio n. 18
0
        public ProductDTO GetProduct(int productId)
        {
            using (var context = new PizzeriaMasterpieceEntities())
            {
                var result = context.Products.Where(p => p.ProductId == productId)
                             .Select(q => new ProductDTO
                {
                    ProductId   = q.ProductId,
                    Description = q.Description,
                    Price       = q.Price,
                    Code        = q.Code,
                    Name        = q.Name,
                    ImagePath   = q.ImagePath,
                    SizeId      = q.SizeId,
                    SizeName    = q.Size.Name,
                    IsActive    = q.IsActive,
                }).FirstOrDefault();

                return(result);
            }
        }
Esempio n. 19
0
        public List <ProductDTO> GetProductList()
        {
            using (var context = new PizzeriaMasterpieceEntities())
            {
                var result = context.Products.Where(p => p.IsActive == 1)
                             .Select(q => new ProductDTO
                {
                    ProductId   = q.ProductId,
                    Description = q.Description,
                    Price       = q.Price,
                    Code        = q.Code,
                    Name        = q.Name,
                    ImagePath   = q.ImagePath,
                    SizeId      = q.SizeId,
                    SizeName    = q.Size.Name
                })
                             .ToList();

                return(result);
            }
        }
Esempio n. 20
0
        public int InsertProduct(ProductDTO product)
        {
            using (var context = new PizzeriaMasterpieceEntities())
            {
                var newProduct = new Product
                {
                    ProductId   = -1,
                    Code        = product.Code,
                    Name        = product.Name,
                    Description = product.Description,
                    Price       = product.Price.Value,
                    ImagePath   = product.ImagePath,
                    SizeId      = product.SizeId,
                    IsActive    = 1,
                };

                context.Products.Add(newProduct);
                context.SaveChanges();
                return(newProduct.ProductId);
            }
        }
        public int InsertOrder(OrderDTO product)
        {
            using (var context = new PizzeriaMasterpieceEntities())
            {
                var newOrder = new Order
                {
                    OrderId        = -1,
                    Date           = product.Date,
                    Address        = product.Address,
                    Remark         = product.Remark,
                    OrderStatusId  = 1,
                    DocumentTypeId = product.DocumentTypeId,
                    UserId         = product.UserId
                };

                var autoId = 0;
                foreach (var item in product.OrderDetails)
                {
                    var newOrderDetail = new OrderDetail
                    {
                        OrderDetailId = --autoId,
                        OrderId       = newOrder.OrderId,
                        Price         = item.Price,
                        ProductId     = item.ProductId,
                        Quantity      = item.Quantity,
                        TotalPrice    = item.Quantity * item.Price
                    };
                    newOrder.OrderDetails.Add(newOrderDetail);
                }

                context.Orders.Add(newOrder);
                context.SaveChanges();

                var currentOrder = context.Orders.Find(newOrder.OrderId);
                currentOrder.OrderNo = "W" + newOrder.OrderId.ToString().PadLeft(9, '0');
                context.SaveChanges();
                return(newOrder.OrderId);
            }
        }
 public UserDTO GetUserByEmail(string email)
 {
     using (var context = new PizzeriaMasterpieceEntities())
     {
         var result = context.Users
                      .Where(p => p.Email == email && p.IsActive == 1)
                      .Select(q => new UserDTO
         {
             UserId      = q.UserId,
             DocumentNo  = q.DocumentNo,
             FirstName   = q.FirstName,
             LastName    = q.LastName,
             Email       = q.Email,
             Address     = q.Address,
             PhoneNumber = q.PhoneNumber,
             RoleId      = q.RoleId,
             RoleName    = q.Role.Name
         })
                      .FirstOrDefault();
         return(result);
     }
 }
        public int InsertUser(UserRegistrationDTO user)
        {
            using (var context = new PizzeriaMasterpieceEntities())
            {
                var newUser = new User
                {
                    UserId      = -1,
                    DocumentNo  = user.DocumentNo,
                    FirstName   = user.FirstName,
                    LastName    = user.LastName,
                    Email       = user.Email,
                    Address     = user.Address,
                    PhoneNumber = user.PhoneNumber,
                    RoleId      = 3,
                    IsActive    = 1,
                    Password    = HashPassword(user.Password)
                };

                context.Users.Add(newUser);
                context.SaveChanges();
                return(newUser.UserId);
            };
        }