/// <summary> /// This is the logic which will Display All Landlords and will separate them in pages and each page will show 20 items. /// </summary> /// <param name="page"></param> /// <returns></returns> public LandlordsViewModel GetAllLandlords(int?page) { LandlordsViewModel model = new LandlordsViewModel(); List <LandlordViewModel> landlordsList = new List <LandlordViewModel>(); var lords = this.Context.Landlords.OrderBy(m => m.Id).ToArray(); if (page == null) { model.Pager = new Pager(lords.Count(), 1, NumberOfItemsInPage); foreach (var item in lords.Take(20)) { LandlordViewModel landlord = Mapper.Map <Landlord, LandlordViewModel>(item); landlordsList.Add(landlord); } model.Landlords = landlordsList; } else { model.Pager = new Pager(lords.Count(), (int)page, NumberOfItemsInPage); model.Landlords = Mapper.Instance.Map <IEnumerable <Landlord>, IEnumerable <LandlordViewModel> >( lords.Skip((model.Pager.CurrentPage - 1) * model.Pager.PageSize).Take(model.Pager.PageSize)); } return(model); }
/// <summary> /// The logic is the same as the EditProperty Action /// </summary> /// <param name="id"></param> /// <returns></returns> public LandlordViewModel EditLandlordById(int id) { var landlord = this.Context.Landlords.Find(id); LandlordViewModel model = Mapper.Map <Landlord, LandlordViewModel>(landlord); return(model); }
public ActionResult EditLandlord([Bind(Include = "Id, FullName, PhoneNumber, IsAcceptingAnimals")] LandlordViewModel landlord) { if (ModelState.IsValid) { this.service.EditLandlordById(landlord); return(this.RedirectToAction($"Show/Landlords", "Properties", new { area = "" })); } return(this.View(landlord)); }
/// <summary> /// The logic is the same as the EditProperty Action /// </summary> /// <param name="id"></param> /// <returns></returns> public void EditLandlordById(LandlordViewModel model) { var landlordToEdit = this.Context.Landlords.Find(model.Id); landlordToEdit.FullName = model.FullName; landlordToEdit.PhoneNumber = model.PhoneNumber; landlordToEdit.IsAcceptingAnimals = model.IsAcceptingAnimals; this.Context.SaveChanges(); }
public ActionResult EditLandlord(int id) { LandlordViewModel landlord = this.service.EditLandlordById(id); if (landlord == null) { return(this.HttpNotFound()); } return(this.View(landlord)); }
public PropertyFormViewModel GeneratePropertyViewModel() { PropertyFormViewModel model = new PropertyFormViewModel(); List <LandlordViewModel> landlordList = new List <LandlordViewModel>(); foreach (var landlord in this.Context.Landlords) { LandlordViewModel lvm = Mapper.Map <Landlord, LandlordViewModel>(landlord); landlordList.Add(lvm); } model.LandlordsList = landlordList; return(model); }
/// <summary> /// Here we fetch our data from the Database by ID and return the model with his data to be Edited, Also we use AutoMapper to Map or Entity models to our View/Binding Models. /// </summary> /// <param name="id"></param> /// <returns></returns> public PropertyFormViewModel EditPropertyById(int id) { var property = this.Context.Properties.Find(id); PropertyFormViewModel model = Mapper.Map <Property, PropertyFormViewModel>(property); List <LandlordViewModel> landlordList = new List <LandlordViewModel>(); foreach (var landlord in this.Context.Landlords) { LandlordViewModel lvm = Mapper.Map <Landlord, LandlordViewModel>(landlord); landlordList.Add(lvm); } model.LandlordsList = landlordList; return(model); }
public ActionResult Edit() { string userid = User.Identity.GetUserId(); int landlord_id = db.Landlords.Where(l => l.ApplicationUserId == userid).First().IDforLand; //int idDecrypted = int.Parse(AppHandler.Decrypt(id)); //if (id == null) //{ // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); //} Landlord landlord = db.Landlords.Find(landlord_id); if (landlord == null) { return(HttpNotFound()); } //ViewBag.ApplicationUserId = new SelectList(db.Users, "Id", "Email", landlord.ApplicationUserId); LandlordViewModel model = new LandlordViewModel { IDforLand = landlord.IDforLand, Title = landlord.Title, Surname = landlord.Surname, OtherNames = landlord.OtherNames, CorporateName = landlord.CorporateName, Address = landlord.Address, Phone = landlord.Phone, RegDate = landlord.RegDate, LandlordID = landlord.LandlordID, Status = landlord.Status, ImageMainUrl = landlord.ImageMainUrl, Facebook = landlord.Facebook, Instagram = landlord.Instagram, MiniBiography = landlord.MiniBiography, HappyClients = landlord.HappyClients, YearsOfExperience = landlord.YearsOfExperience, ApplicationUserId = landlord.ApplicationUserId }; ViewBag.Notification = PropertiesController.notification; return(View(model)); }
public ActionResult Edit(LandlordViewModel model) { var validImageTypes = new string[] { "image/gif", "image/jpeg", "image/pjpeg", "image/png" }; try { if (model.ImageMain != null || model.ImageMain.ContentLength != 0) { if (!validImageTypes.Contains(model.ImageMain.ContentType)) { ModelState.AddModelError("ImageMain", "Please choose either a GIF, JPG or PNG image."); } } } catch (Exception ex) { } if (ModelState.IsValid) { Landlord landlord = new Landlord { IDforLand = model.IDforLand, Title = model.Title, Surname = model.Surname, OtherNames = model.OtherNames, CorporateName = model.CorporateName, Address = model.Address, Phone = model.Phone, RegDate = model.RegDate, LandlordID = model.LandlordID, Status = model.Status, MiniBiography = model.MiniBiography, Facebook = model.Facebook, Instagram = model.Instagram, HappyClients = model.HappyClients, YearsOfExperience = model.YearsOfExperience, ApplicationUserId = model.ApplicationUserId }; try { if (model.ImageMain.ContentLength > 0) { var uploadDir = "/Images"; var imagePath = Path.Combine(Server.MapPath(uploadDir), model.Phone + "_" + model.ImageMain.FileName); var imageUrl = Path.Combine(uploadDir, model.Phone + "_" + model.ImageMain.FileName); model.ImageMain.SaveAs(imagePath); landlord.ImageMainUrl = imageUrl; } } catch (Exception ex) { landlord.ImageMainUrl = model.ImageMainUrl; } db.Entry(landlord).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Home")); } //ViewBag.ApplicationUserId = new SelectList(db.Users, "Id", "Email", landlord.ApplicationUserId); return(View(model)); }