Exemple #1
0
        public async Task <Guid> CreateAuctionWithCategoryNameAsync(AuctionDTO auction, string categoryName)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                auction.CategoryId = (await categoryService.GetCategoryIdsByNamesAsync(categoryName)).FirstOrDefault();
                var auctionId = auctionService.Create(auction);
                await uow.Commit();

                return(auctionId);
            }
        }
        public async Task <Guid> CreateAuctionWithCategoryNameForUserAsync(AuctionDto auction, string userLogin, string categoryName)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                auction.CategoryId = (await _categoryService.GetCategoriesIdsAccordingToNameAsync(new[] { categoryName })).FirstOrDefault();
                auction.SellerId   = (await _userLoginService.GetUserAccordingToUsernameAsync(userLogin)).Id;
                var auctionId = _auctionService.Create(auction);
                await uow.Commit();

                //var delay = auction.EndTime.Subtract(DateTime.Now);
                //BackgroundJob.Schedule(() => CloseAuctionDueToTimeoutAsync(auction), delay);
                //BackgroundJob.Schedule(() => new Func<AuctionDto, Task>(CloseAuctionDueToTimeoutAsync).Invoke(auction), auction.EndTime);
                return(auctionId);
            }
        }
Exemple #3
0
        public IActionResult Create([FromBody] Auction auction)
        {
            try
            {
                if (TryValidateModel(auction) == false)
                {
                    return(BadRequest(ModelState.Values));
                }

                Auction newAuction = _auctionService.Create(auction);
                return(Ok(newAuction));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
Exemple #4
0
        public async Task <int> AddAuctionAsync(CreateAuction auction)
        {
            if (auction == null)
            {
                return(0);
            }
            using (var uow = UnitOfWorkProvider.Create())
            {
                if (await userService.GetAsync(auction.UserId, false) == null)
                {
                    return(0);
                }

                var res = auctionService.Create(auctionService.MapToBase(auction));
                await uow.Commit();

                return(res.Id);
            }
        }
        public async Task <JsonResult> Create(string auction)
        {
            AuctionDto auctionDto = JsonConvert.DeserializeObject <AuctionDto>(auction, new IsoDateTimeConverter {
                DateTimeFormat = "dd.MM.yyyy HH:mm:ss"
            });

            try
            {
                var auc = await _auctionService.Create(auctionDto);

                HttpClient         client  = new HttpClient();
                HttpRequestMessage request = new HttpRequestMessage
                {
                    RequestUri = new Uri("http://localhost:8888/"), //TODO: добавить в конфигурацию и достать оттуда URI
                    Method     = HttpMethod.Post
                };

                request.Headers.Add("Accept", "application/json");

                var aucContent         = new { auc.Id, auc.StartDateTime, auc.EndDateTime, auc.EndPayDateTime };
                var jsonRequestContent = JsonConvert.SerializeObject(aucContent);

                HttpContent content = new StringContent(jsonRequestContent, Encoding.UTF8, "application/json");
                request.Content = content;

                HttpResponseMessage response = await client.SendAsync(request); // отправка запроса и получение ответа

                if (!response.IsSuccessStatusCode)
                {
                    return(Json(new { response = true, success = true, result = auc }));
                }
                else
                {
                    return(Json(new { response = false, success = true, result = auc }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, result = ex.Message }));
            }
        }
        public async Task <ActionResult> Create(AddAuctionModel auctionModel)
        {
            if (ModelState.IsValid)
            {
                var    folder = Guid.NewGuid();
                string photos = null;
                foreach (var file in auctionModel.Photos)
                {
                    if (file != null && file.ContentLength > 0)
                    {
                        var    filename = Guid.NewGuid();
                        string ext      = Path.GetExtension(file.FileName);
                        string path     = $"/upload/{folder}/";
                        Directory.CreateDirectory(Server.MapPath(path));
                        path   = $"{path}{filename}{ext}";
                        photos = $"{photos}:{path}";
                        file.SaveAs(Server.MapPath(path));
                    }
                }
                photos = photos?.Remove(0, 1);

                BllLot lot = new BllLot()
                {
                    AuctionEndDate = auctionModel.AuctionEndDate,
                    Categorie      = int.Parse(auctionModel.Categorie),
                    CreationDate   = DateTime.Now,
                    CurrentPrice   = auctionModel.StartPrice,
                    Description    = auctionModel.Description,
                    LastUpdateDate = DateTime.Now,
                    Photos         = photos,
                    Seller         = await userService.GetId(User.Identity.Name),
                    Title          = auctionModel.Title
                };

                int auctionId = await auctionService.Create(lot);

                return(RedirectToAction("Details", new { id = auctionId }));
            }
            return(View(auctionModel));
        }