示例#1
0
        public void Validate_InvalidFirstArgs_True()
        {
            string[] args   = { "compressTest", _inputPath, _outputPath };
            var      result = ArgumentsValidator.Validate(args);

            Assert.IsFalse(result);
        }
示例#2
0
        /// <summary>
        ///     Provides an option to update an existing advertisement if user is the owner of the advert
        /// </summary>
        /// <param name="advertisment">The advertisement.<seealso cref="Advertisment" /> </param>
        public void UpdateAdvertisment(Advertisment advertisment)
        {
            // Validate arguments
            ArgumentsValidator.Validate(nameof(advertisment), advertisment);
            ArgumentsValidator.Validate(nameof(advertisment.AdvertismentId), advertisment.AdvertismentId);

            Advertisment advert = GetAdvertismentById(advertisment.AdvertismentId.Value);

            if (advert == null)
            {
                throw new ArgumentException("Advertisement not found");
            }

            advert.AdvertismentName        = advertisment.AdvertismentName;
            advert.Category                = advertisment.Category;
            advert.AdvertismentDescription = advertisment.AdvertismentDescription;
            advert.IsBuyNow                = advertisment.IsBuyNow;
            advert.IsAuction               = advertisment.IsAuction;
            advert.IsPromoted              = advertisment.IsPromoted;

            if (advert.IsBuyNow)
            {
                advert.BuyNowPrice = advertisment.BuyNowPrice;
            }

            if (advert.IsAuction)
            {
                advert.CurrentPrice = advertisment.CurrentPrice;
            }

            // update DB with pending changes
            _context.SaveChanges();
        }
        public ActionResult <List <UserMessages> > GetUserMessagesByAdvertismentId(int advertId, string currentUserId)
        {
            try
            {
                ArgumentsValidator.Validate(nameof(currentUserId), currentUserId);

                if (advertId < 1)
                {
                    throw new ArgumentException(
                              MessagingConstants.MessageArgumentWrongValue(nameof(advertId), advertId));
                }

                var response = _messagingService.GetUserMessagesByAdvertismentId(advertId, currentUserId);
                return(StatusCode(200, response));
            }
            catch (ArgumentNullException)
            {
                return(StatusCode(400));
            }
            catch (ArgumentException)
            {
                return(StatusCode(400));
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }
        }
示例#4
0
        public Advertisment GetAdvertismentByUserAndId(string userId, int advertId)
        {
            ArgumentsValidator.Validate(nameof(userId), userId);

            return(_context.Advertisment
                   .FirstOrDefault(a => a.AdvertismentId == advertId && a.UserId == userId));
        }
示例#5
0
        public void Validate_ExcelentArgs_True()
        {
            string[] args   = { "compress", _inputPath, _outputPath };
            var      result = ArgumentsValidator.Validate(args);

            Assert.IsTrue(result);
        }
示例#6
0
        public Advertisment GetAdvertismentById(int advertismentId)
        {
            ArgumentsValidator.Validate(nameof(advertismentId), advertismentId);

            return(_adverismentRepository
                   .GetAdvertismentById(advertismentId));
        }
示例#7
0
        public void Validate_InvalidPathArgs_True()
        {
            _outputPath = "test/test.gz";
            string[] args   = { "compress", _inputPath, _outputPath };
            var      result = ArgumentsValidator.Validate(args);

            Assert.IsFalse(result);
        }
示例#8
0
        public Advertisment GetAdvertimentByUserAndName(string userId, string advertName)
        {
            ArgumentsValidator.Validate(nameof(userId), userId);
            ArgumentsValidator.Validate(nameof(advertName), userId);

            return(_context.Advertisment
                   .FirstOrDefault(a => a.AdvertismentName == advertName && a.UserId == userId));
        }
示例#9
0
        public IEnumerable <Advertisment> GetAdvertismentsByUserCategoryDateRange(string userId, string categoryId,
                                                                                  string expression, DateTime?dateFrom, DateTime?dateTo)
        {
            //ArgumentsValidator.Validate(nameof(userId), userId);
            ArgumentsValidator.Validate(nameof(categoryId), categoryId);

            return(_adverismentRepository.GetAdvertismentsByUserCategoryDateRange(userId, categoryId, expression,
                                                                                  dateFrom, dateTo));
        }
示例#10
0
        /// <summary>
        /// Updates and existing advertisment
        /// </summary>
        /// <param name="saveModel">The save model <seealso cref="AdvertismentSaveModel"/></param>
        public void UpdateAdvertisment(AdvertismentSaveModel saveModel)
        {
            try
            {
                ArgumentsValidator.Validate(nameof(saveModel), saveModel);
                ArgumentsValidator.Validate(nameof(saveModel.AdvertismentName), saveModel.AdvertismentName);

                string requesterId = _userService.GetUserIdForUserNameAsync(saveModel.UserName).Result;

                ArgumentsValidator.Validate(nameof(requesterId), requesterId);

                /**
                 * Check for existing advert name for user requesting operation
                 */

                Advertisment existingAdvertisement = _adverismentRepository.GetAdvertismentByUserAndId(requesterId, saveModel.AdvertismentId.Value);

                if (existingAdvertisement == null)
                {
                    throw new Exception("No advertisement found");
                }

                existingAdvertisement.AdvertismentId          = existingAdvertisement.AdvertismentId;
                existingAdvertisement.AdvertismentName        = saveModel.AdvertismentName;
                existingAdvertisement.AdvertismentDescription = saveModel.Description;
                existingAdvertisement.InitialPrice            = saveModel.InitialPrice;
                existingAdvertisement.IsAuction       = saveModel.IsAuction;
                existingAdvertisement.IsBuyNow        = saveModel.IsBuyNow;
                existingAdvertisement.IsPromoted      = saveModel.IsPromoted;
                existingAdvertisement.BuyNowPrice     = saveModel.BuyNowPrice;
                existingAdvertisement.CurrentPrice    = saveModel.CurrentPrice;
                existingAdvertisement.CreatedDateTime = saveModel.CreatedDateTime;
                existingAdvertisement.CategoryId      = saveModel.CategoryId;
                existingAdvertisement.Status          = saveModel.Status;
                existingAdvertisement.UserId          = requesterId;

                _adverismentRepository.UpdateAdvertisment(existingAdvertisement);
            }
            catch (DbUpdateException ex)
            {
                Log.Warning(ex, AdvertismentConstants.CANNOT_UPDATE_ADVERT);
                throw;
            }
            catch (Exception ex)
            {
                Log.Error(ex, ex.Message);
                throw;
            }
        }
        public ActionResult AcknowledgeNotification(int notificationId, int messageId)
        {
            try
            {
                ArgumentsValidator.Validate(nameof(notificationId), notificationId);
                _notifyService.AcknowledgeNotification(notificationId);
                _messagingService.AcknowledgeMessage(messageId);
            }
            catch (Exception ex)
            {
                Log.Error(ex, ex.Message);
            }

            return(StatusCode(200));
        }
        public ActionResult GetAdvertismentsCount(string userId, int?categoryId, string expression = null)
        {
            ArgumentsValidator.Validate(userId, nameof(userId));
            long count;

            try
            {
                count = _advertismentService.GetAdvertimentsCount(userId, categoryId, expression);
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }

            return(StatusCode(200, count));
        }
        public ActionResult <UserContactInfo> GetAvailableContactsForOwner(int advertId, string ownerId)
        {
            try
            {
                ArgumentsValidator.Validate(nameof(ownerId), ownerId);

                var result = _messagingService.GetAvailableContactsForOwner(advertId, ownerId).Result;
                return(StatusCode(200, result));
            }
            catch (ArgumentNullException)
            {
                return(StatusCode(400));
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }
        }
        public ActionResult <List <UserMessages> > GetAdvertMessagesBetweenOwnerAndUser(int advertId, string ownerId, string targetUserId)
        {
            try
            {
                ArgumentsValidator.Validate(nameof(ownerId), ownerId);
                ArgumentsValidator.Validate(nameof(targetUserId), targetUserId);

                var result = _messagingService.GetAdvertMessagesBetweenOwnerAndUser(advertId, ownerId, targetUserId);
                return(StatusCode(200, result));
            }
            catch (ArgumentNullException)
            {
                return(StatusCode(400));
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }
        }
        public ActionResult GetAdvertisments(AdvertismentSearchModel searchModel)
        {
            try
            {
                List <Advertisment> advertisments = new List <Advertisment>();

                ArgumentsValidator.Validate(nameof(searchModel), searchModel);
                // do not validate as this is optional
                //ArgumentsValidator.Validate(nameof(searchModel.UserId), searchModel.UserId);

                if (!searchModel.CategoryId.HasValue)
                {
                    advertisments = _advertismentService.GetAdvertisments(searchModel.Expression, searchModel.UserId)
                                    .ToList();
                }

                if (searchModel.CategoryId.HasValue)
                {
                    advertisments = _advertismentService
                                    .GetAdvertismentsByUserCategoryDateRange(searchModel.UserId,
                                                                             searchModel.CategoryId.Value.ToString(), searchModel.Expression, searchModel.StartDate,
                                                                             searchModel.EndDate)
                                    .ToList();
                }

                return(StatusCode(200, AdvertHelper.TranslateToResponseObject(advertisments)));
            }
            catch (ArgumentException ex)
            {
                Log.Error(ex, AdvertismentConstants.ARGUMENT_NULL);
                return(StatusCode(400));
            }
            catch (DbUpdateException)
            {
                return(new StatusCodeResult(507));
            }
            catch (Exception)
            {
                return(new StatusCodeResult(500));
            }
        }
        public ActionResult GetNotifications(string userId, params ActivityTypes[] activityTypes)
        {
            List <Notification> notifications = null;

            try
            {
                ArgumentsValidator.Validate(nameof(userId), userId);
                ArgumentsValidator.Validate(nameof(activityTypes), activityTypes);

                notifications = _notifyService.GetNotifications(userId, activityTypes);
            }
            catch (ArgumentException ex)
            {
                Log.Error(ex, ex.Message);
            }
            catch (Exception ex)
            {
                Log.Error(ex, $"Something went wrong during {nameof(GetNotifications)} operation.");
                return(StatusCode(500, ex));
            }

            return(StatusCode(200, notifications));
        }
        private int GetHttpRequestMethodTypeCode(string httpMethodType)
        {
            ArgumentsValidator.Validate(httpMethodType, nameof(httpMethodType));

            switch (httpMethodType)
            {
            case "GET":
                return((int)HttpMethod.Get);

            case "POST":
                return((int)HttpMethod.Post);

            case "PUT":
                return((int)HttpMethod.Put);

            case "PATCH":
                return((int)HttpMethod.Patch);

            case "DELETE":
                return((int)HttpMethod.Delete);

            default: return(-1);
            }
        }
示例#18
0
        public long GetAdvertimentsCount(string userId, int?categoryId, string expression = null)
        {
            ArgumentsValidator.Validate(userId, nameof(userId));

            return(_adverismentRepository.GetAdvertismentsCount(userId, categoryId, expression));
        }
        public void ArgumentsValidation(string[] args, string[] texts)
        {
            _argumentsValidator.Validate(args);

            Assert.Equal(texts, _argumentsValidator.Texts);
        }