public ActionResult Save(PMS.Entities.ProductDTO dto)////////////////////////////// { if (SessionManager.IsValidUser) { if (SessionManager.User.IsAdmin == false /*.IsAdmin == false*/) { TempData["Message"] = "Unauthorized Access"; return(Redirect("~/Home//NormalUser")); } } else { return(Redirect("~/Home/login")); } var uniqueName = ""; if (Request.Files["Image"] != null) { var file = Request.Files["Image"]; if (file.FileName != "") { var ext = System.IO.Path.GetExtension(file.FileName); //Generate a unique name using Guid uniqueName = Guid.NewGuid().ToString() + ext; //Get physical path of our folder where we want to save images var rootPath = Server.MapPath("~/UploadedFiles"); var fileSavePath = System.IO.Path.Combine(rootPath, uniqueName); // Save the uploaded file to "UploadedFiles" folder file.SaveAs(fileSavePath); dto.PictureName = uniqueName; } } //if (dto.ProductID > 0) //{ // dto.ModifiedOn = DateTime.Now; // dto.ModifiedBy = "1"; //} //else //{ // dto.CreatedOn = DateTime.Now; // dto.CreatedBy = "1"; //} BAL.ProductBO.Save(dto); TempData["Msg"] = "Record is saved!"; // return RedirectToAction("ShowAll"); return(Redirect("~/Product2/New")); }
public JsonResult Save(PMS.Entities.ProductDTO dto) { var uniqueName = ""; if (Request.Files["Image"] != null) { var file = Request.Files["Image"]; if (file.FileName != "") { var ext = System.IO.Path.GetExtension(file.FileName); //Generate a unique name using Guid uniqueName = Guid.NewGuid().ToString() + ext; //Get physical path of our folder where we want to save images var rootPath = Server.MapPath("~/UploadedFiles"); var fileSavePath = System.IO.Path.Combine(rootPath, uniqueName); // Save the uploaded file to "UploadedFiles" folder file.SaveAs(fileSavePath); dto.PictureName = uniqueName; } } //if (dto.ProductID > 0) //{ // dto.ModifiedOn = DateTime.Now; // dto.ModifiedBy = "1"; //} //else //{ // dto.CreatedOn = DateTime.Now; // dto.CreatedBy = "1"; //} var pid = EAD_Project.BAL.ProductBO.Save(dto); var data = new { success = true, ProductID = pid, PictureName = dto.PictureName }; return(Json(data, JsonRequestBehavior.AllowGet)); }
public static List <PMS.Entities.SellDTO> GetProductForSell() { var query = String.Format("Select * from dbo.addToCart "); using (DBHelper helper = new DBHelper()) { var reader = helper.ExecuteReader(query); // List<PMS.Entities.ProductDTO> list = new List<PMS.Entities.ProductDTO>(); List <PMS.Entities.SellDTO> list = new List <PMS.Entities.SellDTO>(); List <PMS.Entities.ProductDTO> ProductDTOlist = new List <PMS.Entities.ProductDTO>(); List <PMS.Entities.UserDTO> UserDTOlist = new List <PMS.Entities.UserDTO>(); PMS.Entities.SellDTO s; var dto = new PMS.Entities.ProductDTO(); var dto1 = new PMS.Entities.UserDTO(); // dto.ProductID = reader.GetInt32(0); while (reader.Read()) { dto.ProductID = reader.GetInt32(1); dto1.UserID = reader.GetInt32(2); if (dto != null) { s = new PMS.Entities.SellDTO(); s.Users = GetUserById(dto1.UserID); UserDTOlist.Add(s.Users); PMS.Entities.ProductDTO P1 = GetProductById(dto.ProductID); s.Products = P1; ProductDTOlist.Add(P1); list.Add(s); //s.Products.Add(GetProductById(dto.ProductID)); } } //for (int i = 0; i < s.Count; i++) //{ // list.Add(s[i]); //} // list.Add(s); return(list); } }
private static PMS.Entities.ProductDTO FillDTO(SqlDataReader reader) { var dto = new PMS.Entities.ProductDTO(); dto.ProductID = reader.GetInt32(0);//////////////////// dto.Name = reader.GetString(1); dto.Price = reader.GetInt32(2); dto.PictureName = reader.GetString(3); dto.CreatedOn = reader.GetDateTime(4); dto.CreatedBy = reader.GetString(5); if (reader.GetValue(6) != DBNull.Value) { dto.ModifiedOn = reader.GetDateTime(6); } if (reader.GetValue(7) != DBNull.Value) { dto.ModifiedBy = reader.GetString(7); } dto.IsActive = reader.GetBoolean(8); return(dto); }
public static int Save(PMS.Entities.ProductDTO dto) { using (DBHelper helper = new DBHelper()) { String sqlQuery = ""; if (dto.ProductID > 0) { sqlQuery = String.Format("Update dbo.Products Set Name='{0}',Price='{1}',PictureName='{2}',ModifiedOn='{3}',ModifiedBy='{4}' Where ProductID={5}", dto.Name, dto.Price, dto.PictureName, dto.ModifiedOn, dto.ModifiedBy, dto.ProductID); helper.ExecuteQuery(sqlQuery); return(dto.ProductID); } else { sqlQuery = String.Format("INSERT INTO dbo.Products(Name, Price, PictureName, CreatedOn, CreatedBy,IsActive) VALUES('{0}','{1}','{2}','{3}','{4}',{5}); Select @@IDENTITY", dto.Name, dto.Price, dto.PictureName, dto.CreatedOn, dto.CreatedBy, 1); var obj = helper.ExecuteScalar(sqlQuery); return(Convert.ToInt32(obj)); } } }
public static List <PMS.Entities.ProductDTO> GetProductByUserId(int id) { var query = String.Format("Select * from dbo.addToCart Where UserID={0}", id); using (DBHelper helper = new DBHelper()) { var reader = helper.ExecuteReader(query); List <PMS.Entities.ProductDTO> list = new List <PMS.Entities.ProductDTO>(); var dto = new PMS.Entities.ProductDTO(); while (reader.Read()) { dto.ProductID = reader.GetInt32(1); PMS.Entities.ProductDTO P1 = GetProductById(dto.ProductID); //dto = FillDTO(reader); if (dto != null) { list.Add(P1); } } return(list); } }