public ProductWindow(ProductsDTO product, BLL.BLL BLL_) { InitializeComponent(); LoadData(product); this.product = product; this.BLL_ = BLL_; }
private JArray GetSelectors(ProductsDTO product) { if (product.Variants.Any(_ => !string.IsNullOrEmpty(_.Color)) && product.Variants.Any(_ => !string.IsNullOrEmpty(_.Capacity))) { return(new JArray ( new JObject { { "spec_id", "color" } }, new JObject { { "spec_id", "capacity" } } )); } else if (product.Variants.Any(_ => !string.IsNullOrEmpty(_.Color))) { return(new JArray ( new JObject { { "spec_id", "color" } } )); } else if (product.Variants.Any(_ => !string.IsNullOrEmpty(_.Capacity))) { return(new JArray ( new JObject { { "spec_id", "capacity" } } )); } return(new JArray()); }
public ActionResult EditProduct(int id) { //deklarisanje productVM-a ProductsVM model; using (ShoppingCartDB db = new ShoppingCartDB()) { //pronaci product ProductsDTO dto = db.Products.Find(id); //proveriti da li postoji if (dto == null) { return(Content("This item doesn't exists")); } //inicijalizovati model model = new ProductsVM(dto); //napraviti select listu model.Categories = new SelectList(db.Categories.ToList(), "Id", "Name"); //uzeti sve slike iz glaerije model.GalleryImages = Directory.EnumerateFiles(Server.MapPath("~/Images/Uploads/Products/" + id + "/Gallery/Thumbs")).Select(x => Path.GetFileName(x)); } //vratit view sa modelom return(View(model)); }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["productidd"] != null) { string masp = Request.QueryString["productidd"].ToString().Trim(); _product = _SP.getProductById(masp); Add_Cart(); } if (Session["Search"] != null) { if (_SP.SearchProductByName(Session["Search"].ToString()) != null) { rp_products.DataSource = _SP.SearchProductByName(Session["Search"].ToString()); rp_products.DataBind(); lbKetqua.Text = "Kết quả tìm kiểm cho: " + Session["Search"].ToString(); } else { lbKetqua.Text = "Không tìm thấy kết quả cho: " + Session["Search"].ToString(); } } else { Response.Redirect("index.aspx"); } }
// GET: Admin/Shop/Orders public ActionResult Orders() { // Init list of OrdersForAdminVM List <OrdersForAdminVM> ordersForAdmin = new List <OrdersForAdminVM>(); using (Db db = new Db()) { // Init list of OrderVM List <OrderVM> orders = db.Orders.ToArray().Select(x => new OrderVM(x)).ToList(); // Loop through list of OrderVM foreach (var order in orders) { // Init product dict Dictionary <string, int> productsAndQty = new Dictionary <string, int>(); // Declare total decimal total = 0m; // Init list of OrderDetailsDTO List <OrderDetailsDTO> orderDetailsList = db.OrderDetails.Where(X => X.OrderId == order.OrderId).ToList(); // Get username UserDTO user = db.Users.Where(x => x.Id == order.UserId).FirstOrDefault(); string username = user.Username; // Loop through list of OrderDetailsDTO foreach (var orderDetails in orderDetailsList) { // Get product ProductsDTO product = db.Products.Where(x => x.Id == orderDetails.ProductId).FirstOrDefault(); // Get product price decimal price = product.Price; // Get product name string productName = product.Name; // Add to product dict productsAndQty.Add(productName, orderDetails.Quantity); // Get total total += orderDetails.Quantity * price; } // Add to ordersForAdminVM list ordersForAdmin.Add(new OrdersForAdminVM() { OrderNumber = order.OrderId, Username = username, Total = total, ProductsAndQty = productsAndQty, CreatedAt = order.CreatedAt }); } } // Return view with OrdersForAdminVM list return(View(ordersForAdmin)); }
/// <summary> /// Returns the product list from Data Base /// </summary> /// <returns>List contains ProductsDTO type values</returns> public static List <ProductsDTO> GetProductsList() { var products = new List <ProductsDTO>(); string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; string commandText = "SELECT * FROM Products"; using (var connection = new SqliteConnection(connectionString)) { connection.Open(); SqliteCommand command = new SqliteCommand(commandText, connection); using (SqliteDataReader reader = command.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { var product = new ProductsDTO() { RequiredId = reader.GetInt32(3), Name = reader.GetString(1), Price = reader.GetInt32(2), Water = reader.GetInt32(4), Coffee = reader.GetInt32(5), Suger = reader.GetInt32(6) }; products.Add(product); } } } } return(products); }
public Product Buscar(int id) { Product ProductObj = new ProductsDTO().GetDTO(id); ProductObj._Categorias = (Categories) new CategoriesDTO().GetDTO(ProductObj.CategoryId); return(ProductObj); }
// GET:: Admin/Shop/EditProduct/id public ActionResult EditProduct(int id) { // Declare the productVM ProductVM model; using (Db db = new Db()) { // Get the product ProductsDTO dto = db.Products.Find(id); //Make sure the product exists if (dto == null) { return(Content("That product does not exist.")); } // init the model model = new ProductVM(dto); // Make a select list model.Categories = new SelectList(db.Categories.ToList(), "id", "Name"); // Get all gallery images model.GalleryImages = Directory.EnumerateFiles(Server.MapPath("~/Images/Uploads/Products/" + id + "/Gallery/Thumbs")) .Select(fn => Path.GetFileName(fn)); } // Return View with model return(View(model)); }
public IActionResult GetProduct(int id) { var product = _IProductRepository.Select(id); return(Ok(ProductsDTO.generateDto(product))); //return View(ProductsDTO.generateDto(product)); }
public List <ProductsDTO> GetAllProducts() { List <ProductsDTO> lstProducts = new List <ProductsDTO>(); using (SqlConnection con = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand(string.Format("SELECT * FROM Products order by createddate desc"), con); cmd.CommandType = CommandType.Text; con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { ProductsDTO productsDTO = new ProductsDTO(); productsDTO.ProductId = Convert.ToString(rdr["ProductId"]); productsDTO.ProductName = Convert.ToString(rdr["ProductName"]); productsDTO.ManufacturerName = Convert.ToString(rdr["ManufacturerName"]); productsDTO.Description = Convert.ToString(rdr["Description"]); productsDTO.Price = Convert.ToString(rdr["Price"]); productsDTO.IsAvailable = Convert.ToBoolean(rdr["IsAvailable"]); productsDTO.IsActive = Convert.ToBoolean(rdr["IsActive"]); productsDTO.CreatedDate = Convert.ToDateTime(rdr["CreatedDate"]); lstProducts.Add(productsDTO); } con.Close(); } return(lstProducts); }
public ActionResult EditProduct(int id) { //Declare productVm ProductsVM model; using (db DB = new db()) { //Get the product ProductsDTO dto = DB.Products.Find(id); //confirm product exists if (dto == null) { return(Content("That product does not exist.")); } //init model model = new ProductsVM(dto); //make a select list model.Categories = new SelectList(DB.Categories.ToList(), "Id", "Name"); //get gallery images model.GalleryImages = Directory.EnumerateFiles(Server.MapPath("~/Images/Uploads/Products/" + id + "/Gallery/Thumbs")) .Select(fn => Path.GetFileName(fn)); } //return view with model return(View(model)); }
public ActionResult PutProduct(ProductsDTO productDTO) { ManufacturingPlan manufacturing = _IManufacturingPlanRepository.Select(productDTO.ManufacturingPlanId); Product product = new Product(new Name(productDTO.Name), manufacturing); return(Ok(_IProductRepository.Update(product))); }
public IActionResult Add(ProductsDTO productsDTO) { ProductDAL ProductDAL = new ProductDAL(); ProductDAL.SaveProduct(productsDTO); return(RedirectToAction("ProductListing")); }
public async Task <IActionResult> Create(CreateProductViewModel model) { if (ModelState.IsValid) { string uniqueFileName = null; if (model.Image != null) { string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Image.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); model.Image.CopyTo(new FileStream(filePath, FileMode.Create)); } var product = new ProductsDTO { Id = model.Id, Name = model.Name, ImagePath = uniqueFileName, ProductType = model.ProductType, Price = model.Price, Quantity = model.Quantity }; var result = await _productsService.AddProduct(product); if (result.Success) { return(RedirectToAction("details", new { id = result.Data })); } return(View()); } return(View()); }
public async Task <Response <int> > AddProduct(ProductsDTO productsDTO) { try { if (productsDTO != null && productsDTO.IsValid) { var result = await _productsRepository.AddOrUpdate(productsDTO); return(result > 0 ? new Response <int> { Success = true, Data = result } : new Response <int> { Success = false, Message = "Failed to Add Product" }); } return(new Response <int> { Success = false, Message = "Invalid Product DTO" }); } catch (Exception ex) { return(new Response <int> { Success = false, Message = ex.GetBaseException().Message }); } }
public ProductsDTO GetProductById(int Id) { using (SqlConnection conn = new SqlConnection(this.connectionString)) using (SqlCommand comm = conn.CreateCommand()) { conn.Open(); ProductsDTO product = new ProductsDTO(); comm.CommandText = "select * from [Products] where Id=@Id"; comm.Parameters.AddWithValue("@Id", Id); SqlDataReader reader = comm.ExecuteReader(); while (reader.Read()) { product = new ProductsDTO { Id = Convert.ToInt32(reader["Id"]), Name = (reader["Name"]).ToString(), CategoryId = Convert.ToInt32(reader["CategoryId"]), Price = Convert.ToInt32(reader["Price"]) }; } return(product); } }
public ApiResponse <ProductsDTO> SearchByName(string name) { if (!string.IsNullOrEmpty(name)) { try { ProductsDTO productsDTO = new ProductsDTO(); productsDTO.Items = this._service.RetrieveAll(d => string.Compare(name, d.Name, true) == 0); return(new ApiResponse <ProductsDTO>() { StatusCode = (int)HttpStatusCode.OK, ErrorMessage = "", Result = productsDTO }); } catch (Exception ex) { return(new ApiResponse <ProductsDTO>() { StatusCode = (int)HttpStatusCode.InternalServerError, ErrorMessage = ex.Message }); } } return(new ApiResponse <ProductsDTO>() { StatusCode = (int)HttpStatusCode.BadRequest, ErrorMessage = "" }); }
public ActionResult Orders() { //Init list of OrderForUserVM List <OrdersForUserVM> ordersForUser = new List <OrdersForUserVM>(); using (db DB = new db()) { //Get user id UsersDTO user = DB.Users.Where(x => x.UserName == User.Identity.Name).FirstOrDefault(); int userId = user.Id; //Init list of OrderVM List <OrderVM> orders = DB.Orders.Where(x => x.UserId == userId).ToArray().Select(x => new OrderVM(x)).ToList(); //Loop through list of OrderVM foreach (var order in orders) { //Init product dictionary Dictionary <string, int> productsAndQty = new Dictionary <string, int>(); //Declare total decimal total = 0m; //Init list of OrderDetailsDTO List <OrderDetailsDTO> orderDetailsDTO = DB.OrderDetails.Where(x => x.OrderId == order.OrderId).ToList(); //Loop though list of OrderDetailsDTO foreach (var orderDetails in orderDetailsDTO) { //Get product ProductsDTO product = DB.Products.Where(x => x.ID == orderDetails.ProductId).FirstOrDefault(); //Get product price decimal price = product.Price; //Get product name string productName = product.Name; //Add to products dictionary productsAndQty.Add(productName, orderDetails.Quantity); //Get total total += orderDetails.Quantity * price; } //Add to ordersForUserVM list ordersForUser.Add(new OrdersForUserVM() { OrderNumber = order.OrderId, Total = total, ProductsAndQty = productsAndQty, CreatedAt = order.CreatedAt }); } } //return view with list of OrderForUserVM return(View(ordersForUser)); }
public IActionResult ProductListing() { ProductDAL ProductDAL = new ProductDAL(); List <ProductsDTO> productList = ProductDAL.GetAllProducts(); ProductsDTO trackDeliveryVM = new ProductsDTO(); return(View(productList)); }
public ActionResult <ProductsDTO> PostProduct(ProductsDTO productDTO) { ManufacturingPlan manufacturing = _IManufacturingPlanRepository.Select(productDTO.ManufacturingPlanId); Product product = new Product(new Name(productDTO.Name), manufacturing); _IProductRepository.Insert(product); return(CreatedAtAction(nameof(GetProduct), new { id = product.Id }, product)); }
public ActionResult AddProduct(ProductsDTO p) { p.SupplierID = (int)Session["SupplierId"]; s.AddProduct(Session["Role"].ToString(), p); return(RedirectToAction("List")); }
//GET /api/productsapi/processeditreturn/products public ActionResult <ProductsDTO> ProcessEditReturn(ProductModel product) { repository.Update(product); ProductModel updateProduct = repository.GetByProductId(product.Id); ProductsDTO productsDTO = new ProductsDTO(product.Id, product.Name, product.Price, product.Description); return(productsDTO); }
public async Task <IActionResult> Index([FromBody] ProductsDTO request) { var doSaveResponse = await _productService.DoSave(new DoSaveRequest { ProductsDTO = request }); return(doSaveResponse.IsSuccess ? new ObjectResult(doSaveResponse.UpdatedProducts) : new ObjectResult(new { Message = doSaveResponse.Message })); }
public static Product ConvertProductToDAL(ProductsDTO p) { return(new Product { CategoryId = p.CategoryId, ProductId = p.ProductId, ProductName = p.ProductName }); }
public ProductsDTO AddProducts(ProductsDTO productsDTO) { var product = Mapper.Map <Products>(productsDTO); var result = _service.AddProducts(product); Commit(); return(Mapper.Map(result, new ProductsDTO())); }
private void UpdateProduct(ProductsDTO productsDTO, Product product) { product.Name = productsDTO.Name; product.ImagePath = productsDTO.ImagePath; product.IsActive = true; product.Quantity = productsDTO.Quantity; product.ProductType = productsDTO.ProductType; product.Price = productsDTO.Price; }
public ActionResult AddProduct(HttpPostedFileBase file, ProductsDTO c) { string realpath = Server.MapPath("/images") + "//" + file.FileName; file.SaveAs(realpath); c.productData.path = file.FileName; _db.products.Add(c.productData); _db.SaveChanges(); return(RedirectToAction("Index", "Products")); }
// GET /api/productsapi/showoneproduct/3 public ActionResult <ProductsDTO> ShowOneProduct(int id) { // get the correct product from the database ProductModel product = repository.GetByProductId(id); //create a new DTO based on the Product ProductsDTO productsDTO = new ProductsDTO(product.Id, product.Name, product.Price, product.Description); //return the DTO instead of the product return(productsDTO); }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["productidd"] != null) { string masp = Request.QueryString["productidd"].ToString().Trim(); _product = _QLSP.getProductById(masp); Add_Cart(); } load_data(); }
public List <Product> Buscar() { List <Product> listaP = new ProductsDTO().GetDTO(); foreach (Product p in listaP) { p._Categorias = (Categories) new CategoriesDTO().GetDTO(p.CategoryId); } return(listaP); }