public IHttpActionResult Post([FromBody] DeliveryCappingGroupModel model)
        {
            if (!_validator.IsValid(model))
            {
                return(_validator.BadRequest());
            }

            var item = _mapper.Map <DeliveryCappingGroup>(model);

            _repository.Add(item);
            _repository.SaveChanges();

            return(Ok(_mapper.Map <DeliveryCappingGroupModel>(item)));
        }
Пример #2
0
        public IHttpActionResult Put([FromUri] string externalId, [FromBody] CreateProduct command)
        {
            if (command != null && externalId != command.Externalidentifier)
            {
                ModelState.AddModelError(nameof(CreateProduct.Externalidentifier), "External Id does not match");
                return(BadRequest(ModelState));
            }

            if (!_productValidator.IsValid(command))
            {
                return(_productValidator.BadRequest());
            }

            var newProduct      = _mapper.Map <Product>(command);
            var productToUpdate = _repository.FindByExternal(externalId).FirstOrDefault();

            if (productToUpdate == null)
            {
                productToUpdate     = newProduct;
                productToUpdate.Uid = Guid.NewGuid();
                _repository.Add(productToUpdate);
            }
            else
            {
                productToUpdate.Update(newProduct);
                _repository.Update(productToUpdate);
            }

            _repository.SaveChanges(); // Do not remove this, need to persist changes now so that we can return ProductModel

            return(Ok(_mapper.Map <ProductModel>(productToUpdate)));
        }
Пример #3
0
        public IHttpActionResult PutDefault([FromUri] int id, [FromBody] UpdateAutopilotSettingsModel command)
        {
            if (command != null && id != command.Id)
            {
                ModelState.AddModelError(nameof(UpdateAutopilotSettingsModel.Id), "Model id does not match");
                return(BadRequest(ModelState));
            }

            var autopilotSettings = _autopilotSettingsRepository.Get(id);

            if (autopilotSettings == null)
            {
                return(NotFound());
            }

            if (!_autopilotSettingsValidator.IsValid(command))
            {
                return(_autopilotSettingsValidator.BadRequest());
            }

            autopilotSettings.DefaultFlexibilityLevelId = command.DefaultFlexibilityLevelId;
            autopilotSettings.ScenariosToGenerate       = command.ScenariosToGenerate;
            _autopilotSettingsRepository.Update(autopilotSettings);

            UpdateAutopilotRulesRepository(command.AutopilotRules);

            // Do not remove this, need to persist changes now so that we can return AutopilotSettingsModel
            _autopilotSettingsRepository.SaveChanges();
            _autopilotRuleRepository.SaveChanges();

            return(Ok(Mappings.MapToAutopilotSettingsModel(autopilotSettings, _autopilotRuleRepository, _ruleRepository,
                                                           _ruleTypeRepository, _mapper)));
        }
Пример #4
0
        public async Task <IHttpActionResult> PutAsync(Guid id, [FromBody] UpdateLibrarySalesAreaPassPriorityModel model)
        {
            model.Uid = id;
            if (!_validatorForUpdate.IsValid(model))
            {
                return(_validatorForUpdate.BadRequest());
            }

            LibrarySalesAreaPassPriority entity;

            if (id == Guid.Empty || (entity = await _librarySalesAreaPassPrioritiesRepository.GetAsync(id)) == null)
            {
                return(NotFound());
            }

            //NextGen.Core.Services.IMapper implementation currently doesn't support source and destination mapping hence this code
            _mapper.Map(model, entity);
            await _librarySalesAreaPassPrioritiesRepository.UpdateAsync(entity);

            await _librarySalesAreaPassPrioritiesRepository.SaveChanges();

            var result = _mapper.Map <LibrarySalesAreaPassPriorityModel>(entity);

            result.IsDefault = IsItDefault(result.Uid);
            return(Ok <LibrarySalesAreaPassPriorityModel>(result));
        }
Пример #5
0
        public IHttpActionResult Post(CreateOrUpdateBRSConfigurationTemplateModel model)
        {
            if (!_validator.IsValid(model))
            {
                return(_validator.BadRequest());
            }

            var item = _mapper.Map <BRSConfigurationTemplate>(model);

            item.LastModified = DateTime.UtcNow;

            _repository.Add(item);
            _repository.SaveChanges();

            return(Ok(_mapper.Map <BRSConfigurationTemplateModel>(item)));
        }
Пример #6
0
        public IHttpActionResult Post([FromBody] CreateAnalysisGroupModel newAnalysisGroup)
        {
            if (!_validator.IsValid(newAnalysisGroup))
            {
                return(_validator.BadRequest());
            }

            var item = _mapper.Map <AnalysisGroup>(newAnalysisGroup);

            item.Id         = 0;
            item.CreatedBy  = GetCurrentUserId();
            item.ModifiedBy = item.CreatedBy;

            _analysisGroupRepository.Add(item);
            _analysisGroupRepository.SaveChanges();

            return(Ok(Mappings.MapToAnalysisGroupModel(item, _campaignRepository, _clashRepository, _productRepository,
                                                       _usersRepository, _mapper)));
        }
Пример #7
0
        public async Task <IHttpActionResult> PostAsync([FromBody] CreateLibrarySalesAreaPassPriorityModel model)
        {
            if (!_validatorForCreate.IsValid(model))
            {
                return(_validatorForCreate.BadRequest());
            }

            var entity = _mapper.Map <LibrarySalesAreaPassPriority>(model);

            entity.Uid = Guid.NewGuid();

            await _librarySalesAreaPassPrioritiesRepository.AddAsync(entity);

            await _librarySalesAreaPassPrioritiesRepository.SaveChanges();

            var result = _mapper.Map <LibrarySalesAreaPassPriorityModel>(entity);

            return(CreatedAtRoute <LibrarySalesAreaPassPriorityModel>(RoutePrefix, new { id = result.Uid }, result));
        }
Пример #8
0
        public IHttpActionResult Put([FromBody] UpdateSponsorshipModel updateSponsorshipModel)
        {
            if (updateSponsorshipModel == null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_updateSponsorshipValidator.IsValid(updateSponsorshipModel))
            {
                return(_updateSponsorshipValidator.BadRequest());
            }

            Sponsorship existingsponsorshipitem = _sponsorshipRepository.Get(updateSponsorshipModel.ExternalReferenceId);

            if (existingsponsorshipitem == null)
            {
                return(NotFound());
            }

            UpdateSingleSponsorship(updateSponsorshipModel, existingsponsorshipitem);

            return(Ok());
        }
Пример #9
0
        public IHttpActionResult Post([FromBody] IEnumerable <CreateSponsorshipModel> createSponsorshipModels)
        {
            if (createSponsorshipModels == null || !createSponsorshipModels.Any() || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_createSponsorshipsValidator.IsValid(createSponsorshipModels))
            {
                return(_createSponsorshipsValidator.BadRequest());
            }

            foreach (var sponsorship in createSponsorshipModels.Select(s => _mapper.Map <Sponsorship>(s)))
            {
                sponsorship.DateCreated  = DateTime.UtcNow;
                sponsorship.DateModified = DateTime.UtcNow;
                sponsorship.Uid          = Guid.NewGuid();
                _sponsorshipRepository.Add(sponsorship);
            }

            _sponsorshipRepository.SaveChanges();

            return(Ok());
        }