public IActionResult Index(string province) { var obj = _projectEngine.GetProvinces().FirstOrDefault(i => UrlConverter.ToUrlSlug(i.Name) == province); return(View(new WhereWeViewModel() { CurrentProvince = obj })); }
private string GetUniqueSlugUrl(string FullName, string slugUrl = null, int index = 1) { if (string.IsNullOrWhiteSpace(slugUrl)) { slugUrl = UrlConverter.ToUrlSlug(FullName); } var hasSlug = _userManager.Users.Any(i => i.SlugUrl == slugUrl); if (hasSlug) { return(GetUniqueSlugUrl(FullName, UrlConverter.ToUrlSlug(string.Format("{0}-{1}", FullName, index++)), index++)); } else { return(UrlConverter.ToUrlSlug(slugUrl)); } }
private string GetUniqueSlugUrlForCategory(string CategoryName, string slugUrl = null, int index = 1) { if (string.IsNullOrWhiteSpace(slugUrl)) { slugUrl = UrlConverter.ToUrlSlug(CategoryName); } var hasSlug = _dbContext.Category.Any(i => i.SlugUrl == slugUrl); if (hasSlug) { return(GetUniqueSlugUrl(CategoryName, UrlConverter.ToUrlSlug(string.Format("{0}-{1}", CategoryName, index++)), index++)); } else { return(UrlConverter.ToUrlSlug(slugUrl)); } }
public IActionResult Index(string province, string district) { var pageNumber = 0; var obj = _projectEngine.GetProvinces().FirstOrDefault(i => UrlConverter.ToUrlSlug(i.Name) == province); var districtObj = obj.District.FirstOrDefault(i => UrlConverter.ToUrlSlug(i.Name) == district); if (Request.HasFormContentType && Request.Form.ContainsKey("paging")) { pageNumber = int.Parse(Request.Form["paging"]); } var items = _projectEngine.SearchItems(null, null, provinceId: obj.Id, districtId: districtObj.Id, page: pageNumber); return(View(new WhereWeViewModel() { CurrentProvince = obj, CurrentDistrict = districtObj, Items = items, PageNumber = pageNumber })); }
public TransactionResult CreateItem(string UserId, string categoryslug, string title, string description, string provinceId, string districtId, string whenTypeId, string whenDateId, string whenTimeId, IEnumerable <CategoryQuestions> questions, decimal?price, IEnumerable <IFormFile> galleryImages) { try { var today = DateTime.Now; var item = new Item(); item.Id = Guid.NewGuid(); item.AddedDate = today; item.SlugUrl = UrlConverter.ToUrlSlug(title + "-" + today.DayOfYear + today.Year); var category = _categoryServices.GetCategory(categoryslug); item.CategoryId = category.Id; item.Description = description; int ProvinceId = 0; if (int.TryParse(provinceId, out ProvinceId)) { item.ProvinceId = ProvinceId; } int DistrictId = 0; if (int.TryParse(districtId, out DistrictId)) { item.DistrictId = DistrictId; } int WhenTypeId = 0; if (int.TryParse(whenTypeId, out WhenTypeId)) { item.WhenType = WhenTypeId; } if (!string.IsNullOrWhiteSpace(whenDateId) && !string.IsNullOrWhiteSpace(whenTimeId)) { var datetime = DateTime.ParseExact(whenDateId + " " + whenTimeId, "yyyyMMdd HHmm", CultureInfo.InvariantCulture); item.WhenDate = datetime; } item.Price = price; item.StatusID = (int)StatusTypes.Open; item.Title = title; item.UserId = UserId; item.ItemCategoryQuestionsJSON = JsonConvert.SerializeObject(questions); //// TODO Uncomment here //var upload = new FormUpload(_environment.WebRootPath); //var index = 0; //foreach (var image in galleryImages) //{ // if (image.Length != 0) // { // var filename = string.Format("{0}-{1}", item.Id, index); // var imageResult = upload.SaveFile(image, filename, "itemgallery"); // if (imageResult.Type != TransactionType.Success) // return imageResult; // switch (index) // { // case 0: // item.ImageUrl = imageResult.Result as string; // break; // case 1: // item.ImageUrl2 = imageResult.Result as string; // break; // case 2: // item.ImageUrl3 = imageResult.Result as string; // break; // case 3: // item.ImageUrl4 = imageResult.Result as string; // break; // case 4: // item.ImageUrl5 = imageResult.Result as string; // break; // } // index++; // } //} _dbContext.Item.Add(item); _dbContext.SaveChanges(); _notificationService.AddNotification(UserId, NotificationTypes.CreateItem, itemId: item.Id.ToString()); SendBulkSMS(item); return(new TransactionResult() { Type = TransactionType.Success }); } catch (Exception ex) { return(new TransactionResult(message: "Beklenmedik bir hata oluştu. Lütfen tekrar deneyiniz.", type: TransactionType.Error)); } }