Exemplo n.º 1
0
        /// <summary>
        /// <see cref="IDgtAppService"/>
        /// </summary>
        /// <returns><see cref="IDgtAppService"/></returns>
        public InfractionTypeDTO AddNewInfractionType(InfractionTypeDTO infractionTypeDTO)
        {
            if (infractionTypeDTO == null)
            {
                throw new ArgumentNullException("infractionTypeDTO");
            }

            // Check InfractionType name is not repeated
            var repeatedName = _infractionTypeRepository.GetFiltered(i => i.Name.ToLower() == infractionTypeDTO.Name.ToLower());

            if (repeatedName != null && repeatedName.Any())
            {
                throw new InvalidOperationException(String.Format(CommonMessages.exception_ItemAlreadyExistsWithProperty, Names.InfractionType, Names.Name, infractionTypeDTO.Name));
            }

            // Cast and save item
            var infractionType = MaterializeInfractionTypeFromDto(infractionTypeDTO);

            infractionType.GenerateNewIdentity();
            infractionType.CreatedDate = DateTime.Now;
            infractionType.Validate();

            _infractionTypeRepository.Add(infractionType);
            _infractionTypeRepository.UnitOfWork.Commit();

            return(infractionType.ProjectedAs <InfractionTypeDTO>());
        }
Exemplo n.º 2
0
        public static async Task <InfractionTypeDTO> AddNew(InfractionTypeDTO infractionType)
        {
            using (var client = GetHttpClient())
            {
                var serializeObject = JsonConvert.SerializeObject(infractionType);
                var content         = new StringContent(serializeObject, Encoding.UTF8, "application/json");
                using (var response = await client.PostAsync(URL_KEY, content))
                {
                    if (response.IsSuccessStatusCode)
                    {
                        if (response.Content != null)
                        {
                            var stringResult = await response.Content.ReadAsStringAsync();

                            var result = JsonConvert.DeserializeObject <InfractionTypeDTO>(stringResult);
                            return(result);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        //Logger.Error("Error creando {0} '{1}'.", syncEntity.Singular(), obj.Name);
                        throw new Exception(await CastResultError(response));
                    }
                }
            }
        }
Exemplo n.º 3
0
 public IHttpActionResult Post(InfractionTypeDTO dto)
 {
     try
     {
         var result = this._dgtAppService.AddNewInfractionType(dto);
         return(Ok(result));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Exemplo n.º 4
0
        private InfractionType MaterializeInfractionTypeFromDto(InfractionTypeDTO dto)
        {
            var it = new InfractionType()
            {
                Name        = dto.Name,
                Points      = dto.Points,
                Description = dto.Description
            };

            if (dto.Id != Guid.Empty)
            {
                it.ChangeCurrentIdentity(dto.Id);
            }

            return(it);
        }
Exemplo n.º 5
0
        private async void cmdAccept_Click(object sender, EventArgs e)
        {
            if (this.ValidateData())
            {
                try
                {
                    this._infractionType = await ApiManagerInfractionTypes.AddNew(this._infractionType);

                    this.DialogResult = DialogResult.OK;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ha ocurrido el siguiente error:" + Environment.NewLine + Environment.NewLine + ex.GetBaseException().Message, "DGT", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 6
0
        public InfractionTypeDTO AddNewInfractionType()
        {
            ClearErrors();

            this._infractionType = new InfractionTypeDTO();
            this.infractionTypeDTOBindingSource.DataSource = this._infractionType;
            this.infractionTypeDTOBindingSource.MoveFirst();

            var dialogResult = this.ShowDialog();

            if (dialogResult == DialogResult.OK)
            {
                return(this._infractionType);
            }
            else
            {
                return(null);
            }
        }