public async Task <IActionResult> HandleInfo(House house, string cancel) { //when click button Cancel, references to ViewNewsList View if (cancel == "Cancel") { List <House> ListNewsHouse = GetAllInfoHouse(); ViewBag.List = ListNewsHouse; return(View("ViewNewsList")); } //when click button Ok to submit //check validation fields if (ModelState.IsValid) { //Id = 0 => Create new Entity if (house.Id == 0) { _houseRepository.AddHouse(house); } else { //Id != 0 => Update has Entity _houseRepository.UpdateHouse(house); } int idImage = _houseRepository.GetMaxId(); //save image and get image name for (int i = 0; i < house.ListImageFile.Count; i++) { IFormFile image = house.ListImageFile[i]; var filePath = Path.Combine(_he.WebRootPath, "images", Path.GetFileName(image.FileName)); using (var stream = new FileStream(filePath, FileMode.Create)) { await image.CopyToAsync(stream); stream.Flush(); } ImageNameOfHouse imageNameOfHouse = new ImageNameOfHouse { ImageName = image.FileName }; _imageNameRepository.AddImageName(imageNameOfHouse, idImage); } //show news list => references to ViewNewsList View List <House> ListNewsHouse = GetAllInfoHouse(); ViewBag.List = ListNewsHouse; return(View("ViewNewsList")); } //if Validation Model fail => return Index View and notify invalid data else { return(View("Index", house)); } }