Esempio n. 1
0
        public IHttpActionResult Post([FromBody] List <CreateRestriction> command)
        {
            if (!ModelState.IsValid)
            {
                return(this.Error().InvalidParameters());
            }

            Restriction restriction = null;
            var         returnList  = new List <Restriction>();

            foreach (var item in command)
            {
                ValidateInput(item);
                var refItem = item;
                AssignDefaultValue(ref refItem);
                restriction     = _mapper.Map <Restriction>(refItem);
                restriction.Uid = Guid.NewGuid();
                EnsureThatAllSalesAreasAdded(restriction);

                _restrictionRepository.Add(restriction);
                returnList.Add(restriction);
            }

            _restrictionRepository.SaveChanges();
            return(Ok(_mapper.Map <List <RestrictionModel> >(returnList)));
        }
        public CreateRestrictionResponse CreateRestriction(CreateRestrictionRequest request)
        {
            CreateRestrictionResponse response = new CreateRestrictionResponse();
            Restriction restriction            = new Restriction();

            restriction.RestrictionName        = request.RestrictionName;
            restriction.RequirePermission      = request.RequirePermission;
            restriction.RestrictionDescription = request.RestrictionDescription;

            if (restriction.GetBrokenRules().Count() > 0)
            {
                response.Errors = restriction.GetBrokenRules().ToList();
            }
            else
            {
                try {
                    _restrictionRepository.Add(restriction);
                    _uow.Commit();
                    response.Errors = new List <BusinessRule>();
                } catch (Exception ex)
                {
                    List <BusinessRule> errors = new List <BusinessRule>();
                    do
                    {
                        errors.Add(new BusinessRule("DAL", "DAL_ERROR: " + ex.Message));
                        ex = ex.InnerException;
                    } while (ex != null);

                    response.Errors = errors;
                }
            }

            return(response);
        }
 public override Restriction Add(Restriction model)
 {
     _repository.Add(new[] { model });
     return(model);
 }
Esempio n. 4
0
 public Restriction Add(Restriction model)
 {
     _repository.Add(model);
     return(model);
 }