Esempio n. 1
0
        internal void AddOffer(string vehicleID, string driverID, int source, int destinaiton, List <int> viaPoints, byte seats, DateTime startDate, DateTime endDate)
        {
            Offer Offer = SetOffer(vehicleID, driverID, source, destinaiton, viaPoints, seats, startDate, endDate);

            Offer = OfferServices.Create(Offer);
            OfferServices.Add(Offer);
            OfferServices.SaveData();
        }
Esempio n. 2
0
 public IActionResult OnPost()
 {
     if (ModelState.IsValid)
     {
         var newOffer = Offer.ToDomainModel();
         _offerService.Create(newOffer);
         return(RedirectToPage("/Confirmation", "NewOfferCreated"));
     }
     return(Page());
 }
Esempio n. 3
0
        public async Task <int> CreateOfferAsync(OfferDTO offer)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                var offerId = offerService.Create(offer);
                await uow.Commit();

                return(offerId);
            }
        }
        public async Task <IActionResult> Create(OfferCreateViewModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var id = await offerService.Create(input);

            return(RedirectToAction("Details", new { id = id }));
        }
        public async Task <IActionResult> AddOffer([FromForm] OfferBindingModel model)
        {
            Result result;

            if (!ModelState.IsValid)
            {
                result = new Result
                {
                    IsSuccess = false,
                    EntityId  = Guid.Empty,
                    Error     = "Ошибка в заполненной форме"
                };

                return(BadRequest(JsonConvert.SerializeObject(result, Formatting.None, new JsonSerializerSettings
                {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                })));
            }

            result = await _offerService.Create(_mapper.Map <OfferDto>(model), User.Identity.Name !);

            if (result.IsSuccess)
            {
                var offerPhotos = new List <PhotoDto>();
                foreach (var photo in model.Photos)
                {
                    if (photo != null)
                    {
                        byte[] imageData = null;
                        using var binaryReader = new BinaryReader(photo.OpenReadStream());
                        imageData = binaryReader.ReadBytes((int)photo.Length);

                        offerPhotos.Add(new PhotoDto
                        {
                            Image   = imageData,
                            OfferId = result.EntityId
                        });
                    }
                }

                if (offerPhotos.Count > 0)
                {
                    result = await _photoService.Save(offerPhotos, result.EntityId);
                }
            }

            return(Ok(JsonConvert.SerializeObject(result, Formatting.None, new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            })));
        }