public ActionResult AddNoticeToDatabase(NewNoticeViewModel model) { try { var newNoticeToAdd = new NoticeEntity(); newNoticeToAdd.Amount = decimal.Parse(model.Amount); newNoticeToAdd.CategoryId = int.Parse(model.SelectedCategoryId); newNoticeToAdd.CreateDate = DateTime.Now; newNoticeToAdd.Description = model.Description; newNoticeToAdd.ExprireDate = DateTime.Now.AddDays(int.Parse(model.ExpireTo)); newNoticeToAdd.NoticePlaceId = int.Parse(model.NoticePlaceId); newNoticeToAdd.Title = model.Title; newNoticeToAdd.UserProfileId = WebMatrix.WebData.WebSecurity.CurrentUserId; var noticeRepo = new NoticeRepository(); noticeRepo.AddNewNotice(newNoticeToAdd); ViewBag.Message = "Dodano ogłoszenie."; } catch (Exception ex) { ViewBag.Message = "Ups coś poszło nie tak."; ViewBag.ExtendMessage = ex.Message; } return View(); }
public ActionResult ShowNoticeDetails(int noticeId) { var categoryRepo = new CategoryRepository(); var allCategory = categoryRepo.GetAllCategory(); var noticeRepo = new NoticeRepository(); var currentNotice = noticeRepo.GetNoticeById(noticeId); var result = new NoticeDetailsViewModel(); result.CategoriesList = allCategory; result.Notice = currentNotice; return View(result); }
public ActionResult Index(Nullable<int> categoryId = null) { var categoryRepo = new CategoryRepository(); var allCategory = categoryRepo.GetAllCategory(); var noticeRepo = new NoticeRepository(); var noticesList = new List<NoticeRepo>(); if (categoryId == null) noticesList = noticeRepo.GetAllNotices(); else noticesList = noticeRepo.GetNoticesByCategoryId(categoryId.Value); var result = new HomeViewModel(); result.CategoriesList = allCategory; result.NoticesList = noticesList; result.SelectedCategoryId = categoryId; return View(result); }
public ActionResult EditNotice(int noticeId) { var categoryRepo = new CategoryRepository(); var allCategory = categoryRepo.GetAllCategory(); var noticePlaceRepo = new NoticePlaceRepository(); var allNoticePlace = noticePlaceRepo.GetAllNoticePlace(); var result = new NewNoticeViewModel(); var categoryListTemporary = new List<SelectListItem>(); foreach (var category in allCategory) { categoryListTemporary.AddRange(category.SubCategory.Select(x => new SelectListItem { Text = string.Format("{0}, {1}", category.Name, x.Name), Value = x.Id.ToString() })); } result.CategoryList = categoryListTemporary; result.NoticePlaceList = allNoticePlace.Select(x => new SelectListItem { Text = string.Format("{0}, {1}", x.Province, x.City), Value = x.Id.ToString() }).OrderBy(x => x.Text); var noticeRepo = new NoticeRepository(); var currentNotice = noticeRepo.GetNoticeById(noticeId); result.Title = currentNotice.Title; result.Amount = currentNotice.Amount.ToString(); result.Description = currentNotice.Description; //result.ExpireTo = currentNotice.Title; result.SelectedCategoryId = currentNotice.CategoryId.ToString(); result.NoticePlaceId = currentNotice.NoticePlaceId.ToString(); result.Id = currentNotice.Id; return View(result); }
// // GET: /UserNotices/ public ActionResult Index() { var noticeRepo = new NoticeRepository(); var noticesList = new List<NoticeRepo>(); noticesList = noticeRepo.GetNoticesByUserId(); return View(noticesList); }