Esempio n. 1
0
        public ActionResult Create([FromBody] CommissionDTO dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = _userRepository.GetById(this.UserId);

            var entity = _mapper.Map <Commission>(dto);

            entity.User = user;

            int orderRandom;

            do
            {
                orderRandom = Helpers.RandomNumber6digits('1');
            } while (_repository.IsOrder(orderRandom));

            entity.Order = orderRandom;

            _repository.Create(entity);
            _repository.Save();

            return(Ok(_mapper.Map <CommissionDTO>(entity)));
        }
        public void AddCommission()
        {
            var locationId = _icr.GetLocationViewModels().ToList().Count;

            if (ValidateInput())
            {
                _icr.CreateLocation(new LocationViewModel(locationId, ZipCode, StreetNumber, SelectedRegion));
                Commission = new CommissionViewModel(_icr.GetAll().ToList().Count + 1, Frequency, SelectedCustomer.Id, locationId, null, DateTime.Now, null, Description, SelectedRegion, SelectedCustomer.Name);
                if (_icr.Create(Commission))
                {
                    _cvm.CommissionList.Add(Commission);

                    _router.SetViewCommand.Execute("commissions-overview");
                }
            }
            else
            {
                ShowValidationError();
            }
        }