コード例 #1
0
 public ActionResult Transform(int id)
 {
     Helpers.SessionHelper.SetSession("ConsignmentId", id);
     var consig = db.Consignments.Find(id);
     var trans = new Product(){
         Description = consig.Description,
         Price = consig.Price,
     };
     var fisrtDis = db.Districts.First();
     ViewBag.WardID = new SelectList(fisrtDis.Wards, "WardID", "WardName", fisrtDis.Wards.First().WardID);
     ViewBag.Contact = new SelectList(db.Contacts, "ContactID", "FullName");
     ViewBag.District = new SelectList(db.Districts.ToList(), "DistrictID", "DistrictName", fisrtDis.DistrictID);
     return View(trans);
 }
コード例 #2
0
        public ActionResult Create(Product product, IEnumerable<HttpPostedFileBase> files, FormCollection collection)
        {
            if (ModelState.IsValid)
            {
                int productID;
                int orderCaption = 1;
                //Create project
                product.CreatedBy = User.Identity.Name;
                product.CreatedDate = DateTime.Now;
                product.UpdatedBy = User.Identity.Name;
                product.UpdatedDate = DateTime.Now;
                product.IsActive = true;
                product.IsDelete = false;
                product.IsHired = false;

                db.Products.Add(product);
                db.SaveChanges();

                productID = product.ProductID;


                foreach (var file in files)
                {

                    if (!HasFile(file))
                    {
                        orderCaption++;
                        continue;
                    }

                    ProductImage proImage = new ProductImage();

                    if ((file.ContentType == "image/jpeg") || (file.ContentType == "image/gif") ||
                        (file.ContentType == "image/png" || (file.ContentType == "image/jpg")))//check allow jpg, gif, png, jpeg
                    {
                        // make thumb image
                        Image image = Image.FromStream(file.InputStream);
                        Bitmap thumbImage = new Bitmap(image, 120, 90);

                        // make projet image - product detail page
                        Bitmap projectImage = new Bitmap(image, 480, 360);

                        var fileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
                        var pathImageProject = Path.Combine(Server.MapPath("~/Upload/Images/"), fileName);
                        var pathImageThumb = Path.Combine(Server.MapPath("~/Upload/Thumb/"), fileName);

                        //Save image to ProjectImages folder
                        projectImage.Save(pathImageProject);

                        // Save image to ImageThumb folder
                        thumbImage.Save(pathImageThumb);

                        // Save slide image to ImageSlide

                        // Set ProjectImage model
                        proImage.ImageLink = "/Upload/Images/" + fileName;
                        proImage.Caption = collection["caption" + orderCaption];
                        proImage.ThumblLink = "/Upload/Thumb/" + fileName;

                        proImage.ProductID = productID;

                        // Insert project image to db
                        db.ProductImages.Add(proImage);//add Image object to database (content image path)
                        db.SaveChanges();

                        orderCaption++;// update order
                    }

                }
                var consignID = Helpers.SessionHelper.GetSession("ConsignmentId");
                if (consignID != null)
                {
                    var consign = db.Consignments.Find(Helpers.DataConvertHelper.ToInt(consignID));
                    consign.ProductId = productID;
                    consign.IsSolved = true;
                    consign.UpdatedBy = User.Identity.Name;
                    consign.UpdatedDate = DateTime.Now;
                    db.SaveChanges();
                    Helpers.SessionHelper.ClearSession("ConsignmentId");
                }
                return RedirectToAction("Index");
            }
            int districtid = db.Wards.Find(product.WardID).DistrictID;
            ViewBag.WardID = new SelectList(db.Wards.Where(w => w.DistrictID == districtid), "WardID", "WardName", product.WardID);
            ViewBag.Contact = new SelectList(db.Contacts, "ContactID", "FullName", product.ContactId);
            ViewBag.District = new SelectList(db.Districts.ToList(), "DistrictID", "DistrictName", districtid);
            return View(product);
        }
コード例 #3
0
        public ActionResult Edit(Product product, IEnumerable<HttpPostedFileBase> files, FormCollection collection)
        {
            if (ModelState.IsValid)
            {
                int productID;
                int orderCaption = 1;
                //Create project
                var producrsave = db.Products.Find(product.ProductID);
                if (producrsave != null)
                {
                    producrsave.UpdatedBy = User.Identity.Name;
                    producrsave.UpdatedDate = DateTime.Now;

                    producrsave.ContactId = product.ContactId;
                    producrsave.Description = product.Description;
                    producrsave.DuongTruocNha = product.DuongTruocNha;
                    producrsave.Price = product.Price;
                    producrsave.SoLau = product.SoLau;
                    producrsave.SoPhongNgu = product.SoPhongNgu;
                    producrsave.SoPhongTam = product.SoPhongTam;
                    producrsave.Title = product.Title;
                    producrsave.WardID = product.WardID;
                    producrsave.Dai = product.Dai;
                    producrsave.Ngan = product.Ngan;
                    producrsave.Santhuong = product.Santhuong;
                    db.Entry(producrsave).State = EntityState.Modified;
                    db.SaveChanges();
                    productID = product.ProductID;


                    foreach (var file in files)
                    {

                        if (!HasFile(file))
                        {
                            orderCaption++;
                            continue;
                        }

                        ProductImage proImage = new ProductImage();

                        if ((file.ContentType == "image/jpeg") || (file.ContentType == "image/gif") ||
                            (file.ContentType == "image/png" || (file.ContentType == "image/jpg")))//check allow jpg, gif, png, jpeg
                        {
                            // make thumb image
                            Image image = Image.FromStream(file.InputStream);
                            Bitmap thumbImage = new Bitmap(image, 120, 90);

                            // make projet image - product detail page
                            Bitmap projectImage = new Bitmap(image, 480, 360);

                            var fileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
                            var pathImageProject = Path.Combine(Server.MapPath("~/Upload/Images/"), fileName);
                            var pathImageThumb = Path.Combine(Server.MapPath("~/Upload/Thumb/"), fileName);

                            //Save image to ProjectImages folder
                            projectImage.Save(pathImageProject);

                            // Save image to ImageThumb folder
                            thumbImage.Save(pathImageThumb);

                            // Save slide image to ImageSlide

                            // Set ProjectImage model
                            proImage.ImageLink = "/Upload/Images/" + fileName;
                            proImage.Caption = collection["caption" + orderCaption];
                            proImage.ThumblLink = "/Upload/Thumb/" + fileName;

                            proImage.ProductID = productID;

                            // Insert project image to db
                            db.ProductImages.Add(proImage);//add Image object to database (content image path)
                            db.SaveChanges();

                            orderCaption++;// update order
                        }

                    }

                    return RedirectToAction("Index");
                }
            }
            ViewBag.WardID = new SelectList(db.Wards, "WardID", "WardName", product.WardID);
            ViewBag.Contact = new SelectList(db.Contacts, "ContactID", "FullName", product.ContactId);
            ViewBag.District = new SelectList(db.Districts.ToList(), "DistrictID", "DistrictName", product.Ward.DistrictID);
            return View(product);
        }