public void Load(tblLand model)
 {
     //ds dự án
     ViewBag.ProjectId = new SelectList(db.tblProject, "Id", "Title", model.ProjectId);
     //danh sách hướng
     ViewBag.DirectionId = new SelectList(db.tblDictionary.Where(n => n.CategoryId == 3).ToList(), "Id", "Title", model.DirectionId);
     //danh sách loại giao dịch
     ViewBag.TypeId = new SelectList(db.tblDictionary.Where(n => n.CategoryId == 2).ToList(), "Id", "Title", model.TypeId);
     //loại bất động sản
     ViewBag.CategoryId = new SelectList(db.tblDictionary.Where(n => n.CategoryId == 1).ToList(), "Id", "Title", model.CategoryId);
     //Chọn Tỉnh  ProvinceId
     ViewBag.ProvinceId = new SelectList(db.tblProvince, "Id", "Name", model.ProvinceId);
     //chọn quận huyện
     ViewBag.DistrictId = new SelectList(db.tblDistrict, "Id", "Name", model.DistrictId);
     //chon xã phường
     ViewBag.WardId = new SelectList(db.tblWard, "Id", "Name", model.WardId);
     //pháp lý
     ViewBag.RuleId = new SelectList(db.tblDictionary.Where(n => n.CategoryId == 4).ToList(), "Id", "Title", model.RuleId);
 }
        public ActionResult Create(tblLand model, IEnumerable <HttpPostedFileBase> listImage)
        {
            if (Request["btnSave"] != null)
            {
                model.CreateDate = DateTime.Now;
                model.Area       = Request["DienTich"];
                db.tblLand.Add(model);
                db.SaveChanges();

                var id = model.Id;

                if (listImage != null)
                {
                    foreach (var item in listImage)
                    {
                        if (item == null)
                        {
                            continue;
                        }

                        var newName = item.FileName.Insert(item.FileName.LastIndexOf('.'), $"{DateTime.Now:_ddMMyyyy}");

                        var path = Server.MapPath("~/Uploads/News/" + newName);

                        item.SaveAs(path);

                        var image = new tblImage
                        {
                            Image        = newName,
                            URL          = "/Uploads/News/" + newName,
                            LandId       = id,
                            DictionaryId = 47
                        };
                        db.tblImage.Add(image);
                    }
                }
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            Load(model);
            return(View());
        }
Пример #3
0
        public ActionResult RealAdd(RealViewModel f, HttpPostedFileBase image)
        {
            if (!ModelState.IsValid)
            {
                return(View(f));
            }

            var land = new tblLand
            {
                Address     = f.Address,
                Area        = f.Area,
                Code        = f.BlockCode,
                Content     = f.Content,
                CreateDate  = DateTime.Now,
                CustomerId  = Auth.User.UserId,
                DirectionId = f.DirectionId,
                ProjectId   = f.ProjectId,
                TypeId      = f.TypeId,
                Price       = f.Price,
                ProvinceId  = f.ProvinceId,
                DistrictId  = f.DistrictId,
                UnitId      = f.UnitId,
                Title       = f.Title,
                Email       = f.ClientEmail,
                Phone       = f.ClientCellPhone,
                Road        = f.Facede,
                RuleId      = f.RuleId,
            };

            if (image.AllowFile())
            {
                var newName = image.GetNewFileName();
                image.SaveFileToFolder("/Uploads/Reals/", newName);
                land.Image = "/Uploads/Reals/" + newName;
            }

            _db.tblLand.Add(land);
            _db.SaveChanges();

            return(RedirectToAction("RealIndex"));
        }
        public ActionResult Update(tblLand model, IEnumerable <HttpPostedFileBase> listImage)
        {
            var dba = new LandSoftEntities();
            var la  = dba.tblLand.Find(model.Id);

            if (la == null)
            {
                return(RedirectToAction("Update"));
            }

            foreach (var item in listImage)
            {
                if (item == null)
                {
                    continue;
                }

                var newName = item.FileName.Insert(item.FileName.LastIndexOf('.'), $"{DateTime.Now:_ddMMyyyy}");

                var path = Server.MapPath("~/Uploads/News/" + newName);

                item.SaveAs(path);

                var a = new tblImage
                {
                    Image        = newName,
                    URL          = "/Uploads/News/" + newName,
                    LandId       = model.Id,
                    DictionaryId = 47
                };
                db.tblImage.Add(a);
            }
            model.Area            = string.Empty;
            model.Area            = Request["DienTich"];
            model.CustomerId      = la.CustomerId;
            model.CreateDate      = la.CreateDate;
            db.Entry(model).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }