public static AdsModel GetModel() { AdsModel model = new AdsModel(); string stored = "sp_GetAllAds"; ResultData <DataSet> result = DataAccessHelpers.ExecuteStoredReturnDataSet(stored, null); if (result.Code < 0) { _log.Error(result.Message); } else if (result.Data != null && result.Data.Tables.Count > 0 && result.Data.Tables[0].Rows.Count > 0) { foreach (DataRow row in result.Data.Tables[0].Rows) { model.Parents.Add(new OtherBOL(row)); } if (result.Data.Tables.Count > 1) { foreach (DataRow row in result.Data.Tables[1].Rows) { model.Childrens.Add(new OtherBOL(row)); } } } return(model); }
public async Task <AdsModel> InsertAds(AdsModel ads) { this.context.Ads.Add(ads); await this.context.SaveChangesAsync(); return(ads); }
public virtual ActionResult Manage(int?Id) { AdsModel model; if (Id.HasValue) { var dbAd = _adsBiz.GetList().SingleOrDefault(a => a.Id == Id.Value); model = dbAd.ToViewModel <AdsModel>(); model.SelectedCategories = dbAd.Categories.Select(c => c.Id).ToList(); model.SelectedTags = dbAd.Tags.Select(c => c.Id).ToList(); ViewBag.Tags = dbAd.Tags.Select(c => new TagViewModel { Id = c.Id, Title = c.Title }).ToList(); model.CreationDate = model.CreationDate.ToPersian(); model.ExpireDate = model.ExpireDate.ToPersian(); } else { model = new AdsModel(); } var cats = _categoryBusiness.GetList().Where(c => c.Active).Select(c => new MnTitleValue() { Title = c.Title, Value = c.Id }).ToList(); ViewBag.Categories = cats; //if (!model.SelectedCategories.Any()) // model.SelectedCategories.Add(cats.First().Value); return(View(model)); }
public virtual JsonResult Manage(AdsModel model) { model.CreationDate = model.CreationDate.ToEnglish(); model.ExpireDate = model.ExpireDate.ToEnglish(); var res = new OperationStatus(); if (ModelState.IsValid) { Ad ads; if (model.Id > 0) { var dbAds = _adsBiz.GetList().SingleOrDefault(a => a.Id == model.Id); ads = model.ToModel <Ad>(dbAds); } else { ads = model.ToModel <Ad>(); } if (model.SelectedCategories != null) { ads.Categories.AddEntities(_categoryBusiness.GetList(model.SelectedCategories.ToList()).ToList()); } if (model.SelectedTags != null) { ads.Tags.AddEntities(_tagBusiness.GetList().Where(t => model.SelectedTags.Contains(t.Id)).ToList()); } res = _adsBiz.CreateEdit(ads); } return(Json(res.ToJOperationResult(), JsonRequestBehavior.AllowGet)); }
public async Task <IActionResult> Ads(AdsModel model) { var method = new BaseCommands { Method = "Ads" }; var Variables = new AdsVariables { Url = model.Url }; var Command = new AdsCommand { newVariables = Variables, newBaseCommand = method, }; var bots = new GetBotsByStatusQuery { status = model.Force }; var botlist = await _mediator.Send(bots); var response = CommandExecute.TcpConnects(botlist, JsonConvert.SerializeObject(Command).Replace(@"\", "")); return(Json(OverWriterResponse(response, botlist))); }
public async Task <AdsModel> Create(AdsModel data) { data.ID = Guid.NewGuid(); var result = this._repo.Add(data); return(await result); }
public async Task <AdsModel> Add(AdsModel item) { await this.context.Ads.AddAsync(item); await this.context.SaveChangesAsync(); return(item); }
public async Task <AdsModel> Update(AdsModel item) { if (item != null) { this.context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Modified; await this.context.SaveChangesAsync(); } return(item); }
public IActionResult AddAds(int id) { string userId = User.FindFirstValue(ClaimTypes.NameIdentifier); AdsModel adsModel = new AdsModel { IdCatalog = id, IdCustomer = userId, catalog = repository.GetCatalog(id) }; AdsCreateModel adsCreate = mapper.Map <AdsCreateModel>(adsModel); return(View(adsCreate)); }
public ActionResult Post([FromForm] AdsModel std) { var images = std.Images; int nextAdId = db.Ad.Max(a => a.Id) + 1; Ad ad = new Ad(); ad.Name = std.name; ad.CategoryId = std.categoryId; ad.Price = std.price; ad.UserId = std.userId; ad.Description = std.description; ad.ConditionId = std.conditionId; ad.TypeId = std.typeId; ad.Communication = std.communication; db.Add(ad); foreach (var image in images) { String imageName = image.FileName; if (imageName.Length > 0) { using (var fileStream = new FileStream(imageName, FileMode.Create)) { image.CopyTo(fileStream); var ms = new MemoryStream(); fileStream.CopyTo(ms); AdPhotos adPhotos = new AdPhotos(); adPhotos.Photo = imageName; adPhotos.AdId = nextAdId; db.AdPhotos.Add(adPhotos); db.SaveChanges(); } } } return(Ok(new { status = true, message = "Ad posted successfully!" })); }
public async Task <IActionResult> CreateAds([FromBody] AdsModel value) { return(Ok(await this.vm.CreateAds(value))); }
public async Task <IActionResult> CreateAds([FromBody] AdsModel value) { var result = await this.vm.Create(value); return(Ok(result)); }
public ActionResult EditAdv(AdsModel model, HttpPostedFileBase inputFileImage1, HttpPostedFileBase inputFileImage2, HttpPostedFileBase inputFileImage3, HttpPostedFileBase inputFileImage4, string img1, string img2, string img3, string img4) { var regions = db.Regions.ToList(); List <SelectListItem> listItemsRegions = new List <SelectListItem>(); listItemsRegions = regions.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }).ToList(); ViewBag.regions = listItemsRegions; var types = db.Types.ToList(); List <SelectListItem> listItemsTypes = new List <SelectListItem>(); listItemsTypes = types.Select(x => new SelectListItem { Text = x.Type1, Value = x.Id.ToString() }).ToList(); ViewBag.types = listItemsTypes; var paymenttypes = db.PaymentTypes.ToList(); List <SelectListItem> listItemsPaymentTypes = new List <SelectListItem>(); listItemsPaymentTypes = paymenttypes.Select(x => new SelectListItem { Text = x.PaymentType1, Value = x.Id.ToString() }).ToList(); ViewBag.paymenttypes = listItemsPaymentTypes; var floars = db.Floors.ToList(); List <SelectListItem> listItemsFloars = new List <SelectListItem>(); listItemsFloars = floars.Select(x => new SelectListItem { Text = x.FloorName, Value = x.Id.ToString() }).ToList(); ViewBag.floars = listItemsFloars; var finishings = db.Finishings.ToList(); List <SelectListItem> finishingsTypes = new List <SelectListItem>(); finishingsTypes = finishings.Select(x => new SelectListItem { Text = x.FininshName, Value = x.Id.ToString() }).ToList(); ViewBag.finishings = finishingsTypes; var dbAd = db.Ads.Where(c => c.Id == model.Id).FirstOrDefault(); if (dbAd != null) { dbAd.RegionId = model.Region; dbAd.PhoneNumber1 = model.Phone1; dbAd.PhoneNumber2 = model.Phone2; dbAd.PhoneNumber3 = model.Phone3; dbAd.PhoneNumber4 = model.Phone4; dbAd.AvailableDecrese = model.EnableDiscount; dbAd.CreationDate = DateTime.UtcNow; dbAd.FloarId = model.Floar; dbAd.Description = model.Description; dbAd.EmailAddress = model.Email; dbAd.Name = model.Title; dbAd.Area = model.Area; dbAd.TypeId = model.Type; dbAd.TypePaymentId = model.PaymentType; dbAd.Price = model.Price; dbAd.FinishId = model.Finishing; #region image1 //if the user doesn't change any thing if (!string.IsNullOrEmpty(model.img1)) { } else { //if the user removed it if (!string.IsNullOrEmpty(dbAd.Image1)) { string fullPath = Request.MapPath("~/Pictures/" + dbAd.Image1); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } } if (inputFileImage1 != null) { var fileName = Guid.NewGuid() + Path.GetExtension(inputFileImage1.FileName); var directoryToSave = Server.MapPath(Url.Content("~/Pictures")); var pathToSave = Path.Combine(directoryToSave, fileName); inputFileImage1.SaveAs(pathToSave); dbAd.Image1 = fileName; } else { dbAd.Image1 = null; } } #endregion #region image2 if (!string.IsNullOrEmpty(model.img2)) { } else { //if the user removed it if (!string.IsNullOrEmpty(dbAd.Image2)) { string fullPath = Request.MapPath("~/Pictures/" + dbAd.Image2); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } } if (inputFileImage2 != null) { var fileName = Guid.NewGuid() + Path.GetExtension(inputFileImage2.FileName); var directoryToSave = Server.MapPath(Url.Content("~/Pictures")); var pathToSave = Path.Combine(directoryToSave, fileName); inputFileImage2.SaveAs(pathToSave); dbAd.Image2 = fileName; } else { dbAd.Image2 = null; } } #endregion #region image3 if (!string.IsNullOrEmpty(model.img3)) { } else { //if the user removed it if (!string.IsNullOrEmpty(dbAd.Image3)) { string fullPath = Request.MapPath("~/Pictures/" + dbAd.Image3); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } } if (inputFileImage3 != null) { var fileName = Guid.NewGuid() + Path.GetExtension(inputFileImage3.FileName); var directoryToSave = Server.MapPath(Url.Content("~/Pictures")); var pathToSave = Path.Combine(directoryToSave, fileName); inputFileImage3.SaveAs(pathToSave); dbAd.Image3 = fileName; } else { dbAd.Image3 = null; } } #endregion #region image4 if (!string.IsNullOrEmpty(model.img4)) { } else { //if the user removed it if (!string.IsNullOrEmpty(dbAd.Image4)) { string fullPath = Request.MapPath("~/Pictures/" + dbAd.Image4); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } } if (inputFileImage4 != null) { var fileName = Guid.NewGuid() + Path.GetExtension(inputFileImage4.FileName); var directoryToSave = Server.MapPath(Url.Content("~/Pictures")); var pathToSave = Path.Combine(directoryToSave, fileName); inputFileImage4.SaveAs(pathToSave); dbAd.Image4 = fileName; } else { dbAd.Image4 = null; } } #endregion db.SaveChanges(); return(RedirectToAction("Index")); } return(View(new { adId = model.Id })); //} }
public ActionResult EditAdv(int adid) { AdsModel model = new AdsModel(); model.Id = adid; var regions = db.Regions.ToList(); List <SelectListItem> listItemsRegions = new List <SelectListItem>(); listItemsRegions = regions.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }).ToList(); ViewBag.regions = listItemsRegions; var types = db.Types.ToList(); List <SelectListItem> listItemsTypes = new List <SelectListItem>(); listItemsTypes = types.Select(x => new SelectListItem { Text = x.Type1, Value = x.Id.ToString() }).ToList(); ViewBag.types = listItemsTypes; var paymenttypes = db.PaymentTypes.ToList(); List <SelectListItem> listItemsPaymentTypes = new List <SelectListItem>(); listItemsPaymentTypes = paymenttypes.Select(x => new SelectListItem { Text = x.PaymentType1, Value = x.Id.ToString() }).ToList(); ViewBag.paymenttypes = listItemsPaymentTypes; var floars = db.Floors.ToList(); List <SelectListItem> listItemsFloars = new List <SelectListItem>(); listItemsFloars = floars.Select(x => new SelectListItem { Text = x.FloorName, Value = x.Id.ToString() }).ToList(); ViewBag.floars = listItemsFloars; var finishings = db.Finishings.ToList(); List <SelectListItem> finishingsTypes = new List <SelectListItem>(); finishingsTypes = finishings.Select(x => new SelectListItem { Text = x.FininshName, Value = x.Id.ToString() }).ToList(); ViewBag.finishings = finishingsTypes; var dbAd = db.Ads.Where(c => c.Id == model.Id).FirstOrDefault(); if (dbAd != null) { model.Area = dbAd.Area.Value; model.Description = dbAd.Description; model.Email = dbAd.EmailAddress; model.EnableDiscount = dbAd.AvailableDecrese.Value; model.Finishing = dbAd.FinishId.Value; model.Floar = dbAd.FloarId.Value; model.Id = adid; model.PaymentType = dbAd.TypePaymentId.Value; model.Phone1 = dbAd.PhoneNumber1; model.Phone2 = dbAd.PhoneNumber2; model.Phone3 = dbAd.PhoneNumber3; model.Phone4 = dbAd.PhoneNumber4; model.Price = dbAd.Price.Value; model.Region = dbAd.RegionId.Value; model.Title = dbAd.Name; model.Type = dbAd.TypeId.Value; model.img1 = dbAd.Image1; model.img2 = dbAd.Image2; model.img3 = dbAd.Image3; model.img4 = dbAd.Image4; } return(View(model)); }
public ActionResult CreateAdv(AdsModel model, HttpPostedFileBase inputFileImage1, HttpPostedFileBase inputFileImage2, HttpPostedFileBase inputFileImage3, HttpPostedFileBase inputFileImage4, HttpPostedFileBase inputFileVideo) { string currentusername = SessionPersister.Username; var currentUser = db.UserInfoes.Where(u => u.Username.ToLower() == currentusername.ToLower()).FirstOrDefault(); Ad ad = new Ad() { RegionId = model.Region, PhoneNumber1 = model.Phone1, PhoneNumber2 = model.Phone2, PhoneNumber3 = model.Phone3, PhoneNumber4 = model.Phone4, AvailableDecrese = model.EnableDiscount, CreatedById = currentUser.Id, FloarId = model.Floar, CreationDate = DateTime.UtcNow, Description = model.Description, EmailAddress = model.Email, Name = model.Title, Area = model.Area, TypeId = model.Type, TypePaymentId = model.PaymentType, Price = model.Price, FinishId = model.Finishing }; if (inputFileImage1 != null) { var fileName = Guid.NewGuid() + Path.GetExtension(inputFileImage1.FileName); var directoryToSave = Server.MapPath(Url.Content("~/Pictures")); var pathToSave = Path.Combine(directoryToSave, fileName); inputFileImage1.SaveAs(pathToSave); ad.Image1 = fileName; } if (inputFileImage2 != null) { var fileName = Guid.NewGuid() + Path.GetExtension(inputFileImage2.FileName); var directoryToSave = Server.MapPath(Url.Content("~/Pictures")); var pathToSave = Path.Combine(directoryToSave, fileName); inputFileImage2.SaveAs(pathToSave); ad.Image2 = fileName; } if (inputFileImage3 != null) { var fileName = Guid.NewGuid() + Path.GetExtension(inputFileImage3.FileName); var directoryToSave = Server.MapPath(Url.Content("~/Pictures")); var pathToSave = Path.Combine(directoryToSave, fileName); inputFileImage3.SaveAs(pathToSave); ad.Image3 = fileName; } if (inputFileImage4 != null) { var fileName = Guid.NewGuid() + Path.GetExtension(inputFileImage4.FileName); var directoryToSave = Server.MapPath(Url.Content("~/Pictures")); var pathToSave = Path.Combine(directoryToSave, fileName); inputFileImage4.SaveAs(pathToSave); ad.Image4 = fileName; } if (inputFileVideo != null) { var fileName = Guid.NewGuid() + Path.GetExtension(inputFileVideo.FileName); var directoryToSave = Server.MapPath(Url.Content("~/Pictures")); var pathToSave = Path.Combine(directoryToSave, fileName); inputFileVideo.SaveAs(pathToSave); ad.videoUrl = fileName; } db.Ads.Add(ad); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Ads() { var model = new AdsModel().GetShow(); return(PartialView(model)); }