Example #1
0
        public ActionResult RealEdit(RealViewModel f, HttpPostedFileBase image)
        {
            var r = _db.tblLand.Find(f.Id);

            if (r == null)
            {
                return(HttpNotFound());
            }

            if (!ModelState.IsValid)
            {
                return(View(f));
            }

            r.Address    = f.Address;
            r.Area       = f.Area;
            r.Code       = f.BlockCode;
            r.Content    = f.Content;
            r.CustomerId = Auth.User.UserId;
            r.ProjectId  = f.ProjectId;
            r.Price      = f.Price;
            r.ProvinceId = f.ProvinceId;
            r.DistrictId = f.DistrictId;
            r.Title      = f.Title;
            r.Email      = f.ClientEmail;
            r.Phone      = f.ClientCellPhone;
            r.Road       = f.Facede;

            r.CategoryId  = f.CategoryId;
            r.TypeId      = f.TypeId;
            r.RuleId      = f.RuleId;
            r.UnitId      = f.UnitId;
            r.DirectionId = f.DirectionId;

            if (image.AllowFile())
            {
                if (r.Image != null)
                {
                    FileExtensions.DeleteFile(r.Image.Split('/').Last(), "~/Uploads/Reals/");
                }
                var newName = image.GetNewFileName();
                image.SaveFileToFolder("/Uploads/Reals/", newName);
                r.Image = "/Uploads/Reals/" + newName;
            }

            _db.Entry(r).State = EntityState.Modified;
            _db.SaveChanges();
            TempData["Update"] = "Cập nhật thành công";
            return(RedirectToAction("RealEdit", new { Id = r.Id }));
        }
Example #2
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"));
        }
Example #3
0
        public ActionResult UpdateUser(UserEditViewModel f, HttpPostedFileBase file)
        {
            if (!ModelState.IsValid)
            {
                TempData["Error"] = "Hãy chọn Tình/Thành Phố và Quận/Huyện, Xã/Phường";
                return(RedirectToAction("Index"));
            }
            var user = _db.tblCustomer.FirstOrDefault(t => t.Id == Auth.User.UserId);

            if (user == null)
            {
                Logout();
            }

            user.DistrictId = f.DistrictId;
            user.Phone      = f.Phone;
            user.Skype      = f.Skype;
            user.Birthday   = f.Birthday;
            user.Address    = f.Country;
            user.ProvinceId = f.ProvinceId;
            user.FullName   = f.FullName;
            user.WardId     = f.WardId;
            user.Sex        = f.Gender == EnumGender.Nam ? true : false;

            if (file.AllowFile())
            {
                if (user.Image != null)
                {
                    FileExtensions.DeleteFile(user.Image.Split('/').Last(), "~/Uploads/Avatars/");
                }
                var newName = file.GetNewFileName();
                file.SaveFileToFolder("/Uploads/Avatars/", newName);
                user.Image = "/Uploads/Avatars/" + newName;
            }
            _db.Entry(user).State = EntityState.Modified;
            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }