public void UpdateCountry(Country entity, int Id) { using (PropertyHubContext context = new PropertyHubContext()) { context.Countries.Update(entity); context.SaveChanges(); } }
public void DeleteCity(City entity) { using (PropertyHubContext context = new PropertyHubContext()) { context.Remove(entity); context.SaveChanges(); } }
public void AddCountry(Country entity) { using (PropertyHubContext context = new PropertyHubContext()) { context.Countries.Add(entity); context.SaveChanges(); } }
public void DeleteCountry(Country entity, int Id) { using (PropertyHubContext context = new PropertyHubContext()) { context.Remove(entity); context.SaveChanges(); } }
public PropertyType DeletePropertyTypr(PropertyType entity) { using (PropertyHubContext context = new PropertyHubContext()) { context.PropertyTypes.Remove(entity); context.SaveChanges(); } return(entity); }
public User DeleteUser(User entity) { using (PropertyHubContext context = new PropertyHubContext()) { context.Users.Remove(entity); context.SaveChanges(); } return(entity); }
public void AddCity(City entity) { using (PropertyHubContext context = new PropertyHubContext()) { context.Entry(entity.Province).State = EntityState.Unchanged; context.Add(entity); context.SaveChanges(); } }
public PropertyType AddPropertyTypr(PropertyType entity) { using (PropertyHubContext context = new PropertyHubContext()) { context.PropertyTypes.Add(entity); context.SaveChanges(); } return(entity); }
public void RejectAdv(PropertyAdv entity) { using (PropertyHubContext context = new PropertyHubContext()) { context.Entry(entity.Status).State = EntityState.Unchanged; context.Update(entity); context.SaveChanges(); } }
public Neighborhood DeleteNeighborhood(int id) { using (PropertyHubContext context = new PropertyHubContext()) { Neighborhood found = context.Find <Neighborhood>(id); context.Remove(found); context.SaveChanges(); return(found); } }
public Neighborhood AddNeighborhood(Neighborhood entity) { using (PropertyHubContext context = new PropertyHubContext()) { context.Entry(entity.City).State = EntityState.Unchanged; context.Add(entity); context.SaveChanges(); return(entity); } }
public Neighborhood DeleteNeighborhood(int id) { Neighborhood found = null; using (PropertyHubContext context = new PropertyHubContext()) { found = context.HousingSchemes.Find(id); context.Remove(found); context.SaveChanges(); } return(found); }
public void UpdateCity(City entity, int Id) { using (PropertyHubContext context = new PropertyHubContext()) { City found = context.Find <City>(Id); found.Name = entity.Name; found.Province = entity.Province; context.Entry(entity.Province).State = EntityState.Unchanged; //context.Citys.Update(entity); context.SaveChanges(); } }
public void UpdateProvince(Province entity, int Id) { using (PropertyHubContext context = new PropertyHubContext()) { Province found = context.Find <Province>(Id); found.Name = entity.Name; found.Country = entity.Country; context.Entry(entity.Country).State = EntityState.Unchanged; //context.Provinces.Update(entity); context.SaveChanges(); } }
public IActionResult Update(CreatePropertyAdvModel model) { PropertyHubContext db = new PropertyHubContext(); PropertyAdv entity = model.ToEntity(); string temp = Request.Form["features"]; if (!string.IsNullOrWhiteSpace(temp)) { foreach (var fId in temp.Split(',')) { entity.Features.Add(new PropertyAdvsFeatures { Advertisement = entity, Feature = new PropertyFeature { Id = Convert.ToInt32(fId) } }); } } int counter = 0; foreach (IFormFile file in Request.Form.Files) { if (file.Length > 0) { string ext = file.FileName.Substring(file.FileName.LastIndexOf(".")); string fileName = $"{DateTime.Now.Ticks}_{++counter}{ext}"; string url = $"~/images/p_advs/{fileName}"; string path = hostingEnv.WebRootPath + $@"\images\p_advs\{fileName}"; using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read)) { file.CopyTo(fs); } var find = db.PropertyImage.Where(x => x.Priority.Equals(counter)).FirstOrDefault(); if (find != null && !string.IsNullOrWhiteSpace(find.ImageUrl)) { find.ImageUrl = url; db.SaveChanges(); } else { var findII = db.PropertyImage.OrderByDescending(x => x.Priority).FirstOrDefault(); int count = ++findII.Priority; entity.Images.Add(new PropertyImage { ImageUrl = url, Priority = counter, DateCreated = DateTime.Now }); } } } new PropertyAdvsHandler().UpdatePropertyAdv(entity, model.Id); return(RedirectToAction("manage")); }
public PropertyAdv AddAdvertizement(PropertyAdv entity) { using (PropertyHubContext context = new PropertyHubContext()) { context.Entry(entity.Status).State = EntityState.Unchanged; context.Entry(entity.Type).State = EntityState.Unchanged; context.Entry(entity.Neighborhood).State = EntityState.Unchanged; context.Entry(entity.PostedBy).State = EntityState.Unchanged; context.Entry(entity.Area.PropertyAreaUnit).State = EntityState.Unchanged; context.Add(entity); context.SaveChanges(); return(entity); } }
public User AddUser(User entity) { using (PropertyHubContext context = new PropertyHubContext()) { context.Entry(entity.Address.City).State = EntityState.Unchanged; context.Entry(entity.Address.City.Province).State = EntityState.Unchanged; context.Entry(entity.Address.City.Province.Country).State = EntityState.Unchanged; context.Entry(entity.Role).State = EntityState.Unchanged; context.Users.Add(entity); context.SaveChanges(); } return(entity); }
public User UpdateUser(User entity, int Id) { using (PropertyHubContext context = new PropertyHubContext()) { //City found = context.Find<City>(Id); User found = context.Find <User>(Id); found.Name = entity.Name; found.ContactNumber = entity.ContactNumber; found.Email = entity.Email; context.Entry(found.Id).State = EntityState.Unchanged; context.Entry(found.Role).State = EntityState.Unchanged; context.Users.Update(found); context.SaveChanges(); } return(entity); }
public PropertyAdv UpdatePropertyAdv(PropertyAdv entity, int Id) { using (PropertyHubContext context = new PropertyHubContext()) { PropertyAdv found = (from adv in context.PropertyAdvs where adv.Id == Id select adv).First(); if (!(string.IsNullOrWhiteSpace(entity.Name))) { found.Id = entity.Id; found.Name = entity.Name; found.Price = entity.Price; //found.CityId = entity.Neighborhood.City.Id; //found.AreaUnitId = entity.Area.Unit.Id; //found.AdvType = entity.AdvType.Id; //found.PropertyTypeId = entity.PropertyType.Id; //found.BlockId = entity.Neighborhood.Id; //found.SchemeId = entity.Neighborhood.Parent.Id; //found.StartDate = entity.StartOn; //found.Area = entity.Area; found.Beds = entity.Beds; found.Baths = entity.Baths; } foreach (var item in entity.Images) { found.Images.Add(item); } context.Entry(entity.AdvStatus).State = EntityState.Unchanged; context.Entry(entity.AdvType).State = EntityState.Unchanged; context.Entry(entity.Neighborhood).State = EntityState.Unchanged; context.Entry(entity.PostedBy).State = EntityState.Unchanged; context.Entry(entity.PropertyType).State = EntityState.Unchanged; context.Entry(entity.Area.Unit).State = EntityState.Unchanged; // context.Entry(entity.Images).State = EntityState.Unchanged; foreach (var f in entity.Features) { context.Entry(f.Feature).State = EntityState.Unchanged; } //context.Add(entity); context.SaveChanges(); } return(entity); }
public Neighborhood UpdateNeighborhood(int idToSearch, Neighborhood entity) { using (PropertyHubContext context = new PropertyHubContext()) { Neighborhood found = context.Find <Neighborhood>(idToSearch); found.Name = entity.Name; found.City = entity.City; context.Entry(entity.City).State = EntityState.Unchanged; if (entity.Parent != null) { found.Parent = entity.Parent; context.Entry(entity.Parent).State = EntityState.Unchanged; } context.SaveChanges(); } return(entity); }
public Neighborhood UpdateNeighborhood(int id, Neighborhood area) { using (PropertyHubContext context = new PropertyHubContext()) { Neighborhood found = context.Find <Neighborhood>(id); if (!string.IsNullOrWhiteSpace(area.Name)) { found.Name = area.Name; } if (area.City?.Id != 0) { found.City = area.City; context.Entry(found.City).State = EntityState.Unchanged; } found.Image = area.Image; context.SaveChanges(); return(found); } }
public PropertyAdv AddPropertyAdv(PropertyAdv entity) { using (PropertyHubContext context = new PropertyHubContext()) { context.Entry(entity.AdvStatus).State = EntityState.Unchanged; context.Entry(entity.AdvType).State = EntityState.Unchanged; context.Entry(entity.Neighborhood).State = EntityState.Unchanged; context.Entry(entity.PostedBy).State = EntityState.Unchanged; context.Entry(entity.PropertyType).State = EntityState.Unchanged; context.Entry(entity.Area.Unit).State = EntityState.Unchanged; foreach (var f in entity.Features) { context.Entry(f.Feature).State = EntityState.Unchanged; } context.Add(entity); context.SaveChanges(); } return(entity); }
public Neighborhood UpdateNeighborhood(int idToSearch, Neighborhood neighborhood) { Neighborhood found = null; using (PropertyHubContext context = new PropertyHubContext()) { found = context.HousingSchemes.Find(idToSearch); if (!string.IsNullOrEmpty(neighborhood.Name)) { found.Name = neighborhood.Name; } if (neighborhood.City?.Id != 0) { found.City = neighborhood.City; } if (neighborhood.Blocks != null) { found.Blocks = neighborhood.Blocks; } context.Entry(found.City).State = EntityState.Unchanged; context.SaveChanges(); } return(neighborhood); }