Пример #1
0
        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"));
        }
Пример #2
0
        public IActionResult Create(CreatePropertyAdvModel model)
        {
            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);
                    }
                    entity.Images.Add(new PropertyImage {
                        Priority = counter, ImageUrl = url, DateCreated = DateTime.Now
                    });
                }
            }
            new PropertyAdvsHandler().AddPropertyAdv(entity);
            return(RedirectToAction("manage"));
        }
Пример #3
0
 public IActionResult Delete(CreatePropertyAdvModel model)
 {
     new PropertyAdvsHandler().DeletePropertyAdv(model.ToEntity(), model.Id);
     return(RedirectToAction("Manage"));
 }