Ejemplo n.º 1
0
        public void CreateOffer_TryToCreateOffer_ShouldRepositoryCreateOnce()
        {
            var Offer = new OfferDTO {
                Id = It.IsAny <int>()
            };

            // act
            offerService.CreateOffer(Offer);

            //assert
            offerRepository.Verify(x => x.Create(It.IsAny <Offer>()));
        }
Ejemplo n.º 2
0
        public IHttpActionResult TestOffer()
        {
            string username = "******";
            string userId   = _userService.GetUsers().Where(u => u.UserName.Equals(username)).FirstOrDefault()?.Id;

            Offer offer = new Offer()
            {
                BuyerId      = userId,
                TravellerId  = userId,
                DateCreated  = DateTime.Now,
                DeliveryDate = DateTime.Now,
                IsActive     = true,
                IsDelete     = false,
                PostId       = 1,
                TripId       = 2,
                DateUpdated  = DateTime.Now,
                ShippingFee  = 100
            };

            try
            {
                _offerService.CreateOffer(offer);
                _offerService.SaveOffer();
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));

                throw;
            }
            return(Ok(offer));
        }
Ejemplo n.º 3
0
        public void CreateOffer_TryToCreateOffer_ShouldRepositoryCreateOnce()
        {
            var Offer = new OfferDTO {
                Id = It.IsAny <int>()
            };

            uow.Setup(x => x.Careers.Get(It.IsAny <int>())).Returns(new Career()
            {
            });
            uow.Setup(x => x.Resumes.Get(It.IsAny <int>())).Returns(new Resume()
            {
            });
            // act
            offerService.CreateOffer(Offer);


            //assert
            offerRepository.Verify(x => x.Create(It.IsAny <Offer>()));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create(OfferViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                await _service.CreateOffer(viewModel);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(viewModel));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("OfferId,OfferType,Price,Description")] Offer offer)
        {
            if (ModelState.IsValid)
            {
                await _offerService.CreateOffer(offer);

                return(RedirectToAction(nameof(Create)));
            }
            return(View(offer));
        }
Ejemplo n.º 6
0
 public HttpResponseMessage CreateOffer([FromBody] Offer offer)
 {
     try
     {
         var user = _user.GetUser("needtochangethis");
         return(Request.CreateResponse(HttpStatusCode.Created, _offers.CreateOffer(offer)));
     }
     catch (Exception ex)
     {
         var message = ex.Message;
         return(Request.CreateErrorResponse(HttpStatusCode.Conflict, message));
     }
 }
Ejemplo n.º 7
0
        public async Task <ActionResult> CreateOffer(CreateOfferForm model)
        {
            if (model.DealRate < model.InterestRate)
            {
                ModelState.AddModelError(nameof(model.InterestRate), "Вы превысили максимально допустимую процентную ставку.");
            }

            if (ModelState.IsValid)
            {
                await _offerService.CreateOffer(model, User.Identity.GetUserId <int>());

                return(RedirectToAction("Details", "Deal", new { id = model.DealId }));
            }

            return(View(model));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var offerToCreate = mapper.Map <Offer>(CreateOfferInput);

            if (await offerService.CreateOffer(offerToCreate, CreateOfferInput.OfferPhotos))
            {
                return(RedirectToPage("/Index"));
            }

            Alertify.Push("Offer creating failed", AlertType.Error);
            return(Page());
        }
Ejemplo n.º 9
0
        public ActionResult CreateOffer(Offer offer)
        {
            User user = _session.eMatchUser;

            //TODO: this needs clean up and safety checking
            offer.Expires  = Object.Equals(null, Request["neverExpires"]) ? Convert.ToDateTime(Request["offerExpires"].ToString()) : DateTime.MaxValue;
            offer.Keywords = new List <string>();
            foreach (string item in Request["offerKeywords"].ToString().Split(','))
            {
                offer.Keywords.Add(item);
            }

            offer.ProfileId = _user.GetProfileID(user.Id);
            _offer.CreateOffer(offer);

            return(RedirectToAction("Campaign"));
        }
Ejemplo n.º 10
0
        public IHttpActionResult Add(OfferViewModel offerView)
        {
            try
            {
                offerService.CreateOffer(Mapper.Map <OfferViewModel, OfferDTO>(offerView));

                return(Ok("Offer is created"));
            }
            catch (ArgumentNullException)
            {
                return(BadRequest("Not correct input data"));
            }
            catch (ArgumentOutOfRangeException ex)
            {
                return(BadRequest(ex.ParamName));
            }
        }
Ejemplo n.º 11
0
        public IHttpActionResult PostOfferModel(OfferModel offerModel)
        {
            // Omoguciti dodavanje i izmenu kategorije i prodavca iz ponude
            // Bez Foreign Key svojstava stvari su mnogo komplikovane..
            // Sa Foreign Key JSON koji saljemo je znatno svedeniji ali je i logika bolja

            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}

            //if (!ModelState.IsValid || offerModel.categoryId == null || offerModel.userModel == null)

            // Mladen's code:

            // You also need to update your Model classes. Mladen's solution is to use 'normal' property
            // names and map them to the 'wacky' database column names
            if (!ModelState.IsValid || offerModel.categoryId == null || offerModel.sellerId == null)
            {
                return(BadRequest(ModelState));
            }

            CategoryModel category = categoryService.GetCategory((int)offerModel.categoryId);
            UserModel     seller   = userService.GetUser((int)offerModel.sellerId);

            if (category == null || seller == null)
            {
                return(NotFound());
            }

            if (seller.user_role != UserModel.UserRoles.ROLE_SELLER)
            {
                return(BadRequest("User's role must be ROLE_SELLER"));
            }

            offerModel.category = category;
            offerModel.seller   = seller;
            OfferModel createdOffer = offerService.CreateOffer(offerModel);

            // my old stuff
            // offerService.CreateOffer(offerModel);

            return(CreatedAtRoute("SingleOfferById", new { id = offerModel.id }, offerModel));
        }
Ejemplo n.º 12
0
        public ActionResult Create(CreateOfferViewModel createModel)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(createModel));
            }

            string userId = User.Identity.GetUserId();

            CreateOfferParams createOfferParams = new CreateOfferParams()
            {
                EmployeeId = userId, JobId = createModel.JobId, Text = createModel.Text, ImplementationDays = createModel.DaysToImplement, OfferPayment = createModel.OfferPayment
            };

            _offerService.CreateOffer(createOfferParams);

            _commitProvider.SaveChanges();
            return(Redirect(Request.UrlReferrer.PathAndQuery));
        }
Ejemplo n.º 13
0
        public IActionResult Post([FromBody] OfferViewModel offer)
        {
            IActionResult _result      = new ObjectResult(false);
            GenericResult _offerResult = null;

            try
            {
                Offer _offer = _offerService.CreateOffer(offer.Username, offer.Model, offer.Year, offer.Mileage, offer.Description, offer.Price, offer.Color, offer.Fuel,
                                                         offer.Category, offer.SeatsNb, offer.DoorsNb, offer.Displacement, offer.Gearbox, offer.Drive, offer.Damaged, offer.ABS, offer.Airbags, offer.CentralLock, offer.AirCond,
                                                         offer.StartTime, offer.EndTime, offer.Status, offer.Make, offer.PhotoUri);

                if (_offer != null)
                {
                    _offerResult = new GenericResult()
                    {
                        Succeeded = true,
                        Message   = "Oferta dodana pomyślnie"
                    };
                }
            }
            catch (Exception ex)
            {
                _offerResult = new GenericResult()
                {
                    Succeeded = false,
                    Message   = "Należy wypełnić wszystkie pola"
                };

                _loggingRepository.Add(new Error()
                {
                    Message = ex.Message, StackTrace = ex.StackTrace, DateCreated = DateTime.Now
                });
                _loggingRepository.Commit();
            }

            _result = new ObjectResult(_offerResult);
            return(_result);
        }
Ejemplo n.º 14
0
        public async Task <ActionResult> Create(CreateOfferViewModel model)
        {
            int         currentUserId = User.Identity.GetUserId <int>();
            Game        game          = gameService.GetGameByValue(model.Game);
            UserProfile user          = await userProfileService.GetUserProfileByIdAsync(currentUserId);

            if (ModelState.IsValid && game != null && user != null)
            {
                var offer = Mapper.Map <CreateOfferViewModel, Offer>(model);
                offer.UserProfile = user;
                offer.Game        = game;
                offerService.CreateOffer(offer);
                offerService.SaveOffer();
                if (Request.Url != null)
                {
                    offer.JobId = MarketplaceMVCHangfire.SetDeactivateOfferJob(offer.Id,
                                                                               Url.Action("Activate", "Offer", new { id = offer.Id }, Request.Url.Scheme), TimeSpan.FromDays(30));
                }
                offerService.SaveOffer();
            }

            return(View(model));
        }
Ejemplo n.º 15
0
        public IHttpActionResult MakeOffer(OfferViewModel offerVM)
        {
            string username = Utilities.GetUserNameFromRequest(Request);

            if (username == null)
            {
                return(Unauthorized());
            }
            User user = userService.GetUsers().FirstOrDefault(u => u.UserName.Equals(username));

            if (user == null)
            {
                return(BadRequest("Access Denied"));
            }
            try
            {
                Offer offer = new Offer()
                {
                    PostId       = offerVM.PostId,
                    DateCreated  = DateTime.UtcNow.AddHours(7),
                    IsActive     = true,
                    IsDelete     = false,
                    ShippingFee  = int.Parse(offerVM.ShippingFee),
                    DeliveryDate = DateTime.ParseExact(offerVM.DeliveryDate, "dd/MM/yyyy",
                                                       System.Globalization.CultureInfo.InvariantCulture),
                    TripId      = offerVM.TripId,
                    TravellerId = user.Id,
                    BuyerId     = postService.GetPost(offerVM.PostId)?.UserId,
                    DateUpdated = DateTime.UtcNow.AddHours(7),
                    Message     = offerVM.Message,
                    Type        = (int)OfferType.TravelerOffer
                };
                offerService.CreateOffer(offer);
                offerService.SaveOffer();
                offerVM.Id = offer.Id;

                var con = userService.GetUsers().FirstOrDefault(u => u.Id.Equals(offer.BuyerId))?.SignalConnect;
                if (con != null)
                {
                    notificationService.CreateNotification(new Notification
                    {
                        DateCreated = DateTime.UtcNow.AddHours(7),
                        IsRead      = false,
                        Message     = "Nhận được 1 đề nghị mới",
                        Title       = "Đơn hàng " + offer.Post.ProductName,
                        UserId      = offer.BuyerId
                    });
                    notificationService.SaveNotification();
                    HubUtilities.GetHub().Clients.Client(con).receivedOffer("Nhận được 1 đề nghị mới", offerVM.PostId);
                }
                //update post on redis
                var post = postService.GetPost(offerVM.PostId);
                Utilities.updatePostRedis(post, true);
            }
            catch (Exception)
            {
                return(BadRequest("Can't make offer"));
            }

            return(Ok(offerVM));
        }
Ejemplo n.º 16
0
        public async System.Threading.Tasks.Task <ActionResult> Create(CreateOfferViewModel model, HttpPostedFileBase[] images)
        {
            Tinify.Key = ConfigurationManager.AppSettings["TINYPNG_APIKEY"];
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var currentUserId = User.Identity.GetUserId();
            var userProfile   = _userProfileService.GetUserProfiles(u => u.Id == currentUserId, i => i.ApplicationUser).SingleOrDefault();

            if (userProfile != null)
            {
                var appUser = userProfile.ApplicationUser;
                if (appUser != null)
                {
                    if (!(appUser.EmailConfirmed))
                    {
                        return(HttpNotFound("you are not confirmed email or phone number"));
                    }
                }
            }
            else
            {
                return(View("_CreateOfferConfirmationError"));
            }
            if (userProfile.Offers.Count(o => o.State == OfferState.active) >= 10)
            {
                return(View("CrateOfferLimitError"));
            }
            Offer offer = Mapper.Map <CreateOfferViewModel, Offer>(model);

            Game game         = _gameService.GetGameByValue(model.Game);
            var  gameFilters  = _filterService.GetFilters(f => f.Game.Value == game.Value, i => i.Game, i => i.FilterItems).ToList();
            var  modelFilters = model.FilterValues;
            //var gameFilterItems = _filterItemService.GetFilterItems().Where(f => f.Filter.Game == game).ToList();
            var modelFilterItems = model.FilterItemValues;

            if (modelFilters != null && gameFilters.Count != 0)
            {
                if (game != null && modelFilters.Length == gameFilters.Count)
                {
                    for (int i = 0; i < gameFilters.Count; i++)
                    {
                        if (gameFilters[i].Value != modelFilters[i])
                        {
                            return(View("_CreateOfferFilterError"));
                        }

                        bool isContainsFilterItems = false;
                        foreach (var fItem in gameFilters[i].FilterItems)
                        {
                            if (fItem.Value == modelFilterItems[i])
                            {
                                offer.FilterItems.Add(fItem);
                                offer.Filters.Add(gameFilters[i]);
                                isContainsFilterItems = true;
                            }
                        }
                        if (!isContainsFilterItems)
                        {
                            return(View("_CreateOfferFilterError"));
                        }
                    }
                }
                else
                {
                    return(View("_CreateOfferFilterError"));
                }
            }


            foreach (var image in images)
            {
                if (image != null && image.ContentLength <= 1000000 && (image.ContentType == "image/jpeg" || image.ContentType == "image/png"))
                {
                    var extName  = System.IO.Path.GetExtension(image.FileName);
                    var fileName = $@"{Guid.NewGuid()}{extName}";
                    // сохраняем файл в папку Files в проекте
                    string fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "\\Content\\Images\\Avatars", fileName);
                    var    urlPath  = Url.Content("~/Content/Images/Screenshots/" + fileName);
                    image.SaveAs(fullPath);


                    offer.ScreenshotPathes.Add(new ScreenshotPath {
                        Value = urlPath
                    });
                }
                else
                {
                    offer.ScreenshotPathes.Add(new ScreenshotPath {
                        Value = null
                    });
                }
            }

            offer.GameId        = game.Id;
            offer.UserProfileId = _userProfileService.GetUserProfileById(User.Identity.GetUserId()).Id;
            offer.DateDeleted   = offer.DateCreated.AddDays(offerDays);

            _offerService.CreateOffer(offer);
            _offerService.SaveOffer();

            if (Request.Url != null)
            {
                offer.JobId = MarketHangfire.SetDeactivateOfferJob(offer.Id,
                                                                   Url.Action("Activate", "Offer", new { id = offer.Id }, Request.Url.Scheme), TimeSpan.FromDays(30));
            }

            _offerService.SaveOffer();
            var offerModel = Mapper.Map <Offer, OfferViewModel>(offer);

            return(View("OfferCreated", offerModel));
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> CreateOffer([FromBody] CreateOfferRequest request)
        {
            var result = await offerService.CreateOffer(request);

            return(StatusCode((int)result.Code, result.Value));
        }