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 AddNotice()
        {
            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);
            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);
        }