public void EditOffer(Offer offer)
        {
            OfferValidator validator = OfferValidator.CreateValidator(offer, true);

            validator.Validate();
            repository.EditOffer(offer);
        }
        public void NewOffer(Offer offer)
        {
            OfferValidator validator = OfferValidator.CreateValidator(offer, false);

            validator.Validate();
            repository.NewOffer(offer);
        }
示例#3
0
 public async Task <ActionResult> AddOffer(AddNewOfferViewModel model, HttpPostedFileBase image = null)
 {
     if (ModelState.IsValid)
     {
         OfferValidator offerValidator = new OfferValidator(model);
         var            errorList      = offerValidator.ValidateOffer();
         if (errorList.Count != 0)
         {
             int i = 0;
             foreach (var error in errorList)
             {
                 ModelState.AddModelError(String.Format("{0}", i++), error);
                 return(View(model));
             }
         }
         else
         {
             string username = HttpContext.User?.Identity?.Name;
             if (await OfferAccessor.SaveOfferAsync(Context, model, username, image))
             {
                 return(RedirectToAction("MyOffers", "Offer"));
             }
             else
             {
                 return(View("Error", "Offer"));
             }
         }
     }
     return(View(model));
 }
示例#4
0
        /// <summary> Сохранение или обновление информации по предложению </summary>
        public Boolean Save(Offer offer)
        {
            if (offer == null)
               throw new NullReferenceException("Не указано предложение");

            var result = new OfferValidator(offer).Validate();

            if ((result.Any())||((offer.IdOffer == 0) && (ExistOffers(offer.NameOffer))))
                return false;

            using (var dataManager = factory.GetDataManager(ConcurrencyLock.Optimistic))
            {
                var repository = dataManager.GetRepository<IOfferRepository>();
                repository.Save(offer);
                dataManager.Commit();
            }

            return true;
        }
示例#5
0
        /// <summary> Сохранение или обновление информации по предложению </summary>
        public Boolean Save(Offer offer)
        {
            if (offer == null)
               throw new NullReferenceException("Не указано предложение");
            
            var result = new OfferValidator(offer).Validate();

            if ((result.Any())||((offer.IdOffer == 0) && (ExistOffers(offer.NameOffer))))
                return false;

            using (var dataManager = factory.GetDataManager(ConcurrencyLock.Optimistic))
            {
                var repository = dataManager.GetRepository<IOfferRepository>();
                repository.Save(offer);
                dataManager.Commit();
            }

            return true;
        }
示例#6
0
        /// <summary>
        /// indekser potzrebny do walidacji
        /// </summary>
        /// <param name="columnName"></param>
        /// <returns></returns>
        public string this[string columnName]
        {
            get
            {
                ///przyczyna błędu walidacji
                String         errorMessage = String.Empty;
                OfferValidator ov           = new OfferValidator();
                switch (columnName)
                {
                case "AccommodationName":
                    if (string.IsNullOrWhiteSpace(this.AccommodationName))
                    {
                        errorMessage = "Nazwa nie może być pusta";
                    }
                    break;

                case "Street":
                    if (string.IsNullOrWhiteSpace(this.Street))
                    {
                        errorMessage = "Ulica nie może być pusta";
                    }
                    break;

                case "LocalNumber":
                    if (string.IsNullOrWhiteSpace(this.LocalNumber))
                    {
                        errorMessage = "Numer Lokalu nie może być pusty";
                    }
                    if (!ov.ValidateLocalNumber(this.LocalNumber))
                    {
                        errorMessage = "Nieprawidłowy numer lokalu";
                    }
                    break;

                case "PostalCode":
                    if (string.IsNullOrWhiteSpace(this.PostalCode))
                    {
                        errorMessage = "Kod pocztowy nie może być pusty";
                    }
                    if (!ov.ValidatePostalCode(this.PostalCode))
                    {
                        errorMessage = "Nieprawidłowy kod pocztowy";
                    }
                    break;

                case "City":
                    if (string.IsNullOrEmpty(this.City))
                    {
                        errorMessage = "Nieprawidłowa nazwa miasta";
                    }
                    break;

                case "RoomNumber":
                    if (string.IsNullOrWhiteSpace(RoomNumber) || !ov.ValidateLocalNumber(RoomNumber))
                    {
                        errorMessage = "Nieprawidłowy numer pokoju";
                    }
                    break;

                case "StartDate":
                    if (!ov.ValidateDate(this.StartDate, this.EndDate))
                    {
                        errorMessage = "Nieprawidłowe daty";
                    }
                    break;

                case "EndDate":
                    if (!ov.ValidateDate(this.StartDate, this.EndDate))
                    {
                        errorMessage = "Nieprawidłowe daty";
                    }
                    break;

                case "Price":
                    if (!ov.ValidatePrice(this.Price))
                    {
                        errorMessage = "Nieprawidłowa cena";
                    }
                    break;

                case "AvailiableVacanciesNumber":
                    if (!ov.ValidateNumber(this.AvailiableVacanciesNumber))
                    {
                        errorMessage = "Nieprawidłowa liczba wolnych miejsc";
                    }
                    break;

                case "Description":
                    if (string.IsNullOrEmpty(this.Description))
                    {
                        errorMessage = "Dodaj opis";
                    }
                    break;
                }
                return(errorMessage);
            }
        }