예제 #1
0
        public async Task <IActionResult> Put(int loteId, LoteDto model)
        {
            try
            {
                var lote = await _repository.GetByIdAsync(loteId);

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

                _mapper.Map(model, lote);

                _repository.Update(lote);
                if (await _repository.SaveChanges())
                {
                    return(Created($"/api/lote/{model.Id}", _mapper.Map <LoteDto>(model)));
                }
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Banco de dados falhou {ex.Message}"));
            }
            return(BadRequest());
        }
예제 #2
0
 public IActionResult Put()
 {
     try
     {
         LoteDto lote = new LoteDto();
         if (Request.Form.Files != null && Request.Form.Files.Count > 0)
         {
             lote.Imagen = Request.Form.Files[0];
         }
         lote.LoteId        = Convert.ToInt32(Request.Form["loteId"]);
         lote.Nombre        = Request.Form["nombre"];
         lote.Descripcion   = Request.Form["descripcion"];
         lote.ClienteId     = Request.Form["clienteId"];
         lote.FotoLote      = Request.Form["fotoLote"];
         lote.MunicipioId   = Convert.ToInt32(Request.Form["municipioId"]);
         lote.PrecioBase    = Convert.ToDecimal(Request.Form["precioBase"]);
         lote.SubastaId     = Convert.ToInt32(Request.Form["subastaId"]);
         lote.ValorAnticipo = Convert.ToDecimal(Request.Form["valorAnticipo"]);
         loteService.Edit(lote);
         return(Ok(lote));
     }
     catch (Exception)
     {
         throw;
     }
 }
예제 #3
0
 public IActionResult Post()
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState));
         }
         LoteDto lote = new LoteDto();
         lote.Imagen        = Request.Form.Files[0];
         lote.Nombre        = Request.Form["nombre"];
         lote.Descripcion   = Request.Form["descripcion"];
         lote.ClienteId     = Request.Form["clienteId"];
         lote.MunicipioId   = Convert.ToInt32(Request.Form["municipioId"]);
         lote.PrecioBase    = Convert.ToDecimal(Request.Form["precioBase"]);
         lote.SubastaId     = Convert.ToInt32(Request.Form["subastaId"]);
         lote.ValorAnticipo = Convert.ToDecimal(Request.Form["valorAnticipo"]);
         loteService.Add(lote);
         return(Ok(lote));
     }
     catch (Exception)
     {
         throw;
     }
 }
예제 #4
0
 /// <summary>
 /// Adiciona os lotes caso seja um lote novo.
 /// </summary>
 /// <param name="eventoId"></param>
 /// <param name="model"></param>
 /// <returns>É um void, ou seja, não precisa de retorno, ou seja, não precisa de informar o objeto dentro do sinal de maior e menor</returns>
 public async Task AddLote(int eventoId, LoteDto model)
 {
     try
     {
         var lote = _mapper.Map <Lote>(model);//LE-SE: Vai pegar o "model" que é um "Dto", vai mapear ele para um "Lote" e atribuir a variável "var lote".
         lote.EventoId = eventoId;
         _geralPersist.Add <Lote>(lote);
         await _geralPersist.SaveChangesAsync();
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
예제 #5
0
        private async Task AdicionarLote(int eventoId, LoteDto model)
        {
            try
            {
                var lote = _mapper.Map <Lote>(model);
                lote.EventoId = eventoId;

                _geralPersist.Add <Lote>(lote);

                await _geralPersist.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
예제 #6
0
 public void Delete(LoteDto entity)
 {
     try
     {
         uowService.LoteRepository.Delete(mapper.Map <Lote>(entity));
         uowService.Save();
     }
     catch (ExceptionData)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new ExceptionCore("error al intentar eliminar el lote", ex);
     }
 }
예제 #7
0
 public async Task <IActionResult> Post(LoteDto model)
 {
     try
     {
         var lote = _mapper.Map <Lote>(model);
         _repository.Add(lote);
         if (await _repository.SaveChanges())
         {
             return(Created($"/api/lote/{lote.Id}", _mapper.Map <LoteDto>(lote)));
         }
     }
     catch (System.Exception ex)
     {
         return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Banco de dados falhou {ex.Message}"));
     }
     return(BadRequest());
 }
예제 #8
0
 public void Add(LoteDto dto)
 {
     try
     {
         string fileName = ContentDispositionHeaderValue.Parse(dto.Imagen.ContentDisposition).FileName.Trim('"');
         dto.FotoLote = $"{Guid.NewGuid().ToString()}{Path.GetExtension(fileName)}";
         fileHelper.DownLoadFile("images//LOTES", dto.Imagen, dto.FotoLote);
         uowService.LoteRepository.Add(mapper.Map <Lote>(dto));
         uowService.Save();
     }
     catch (ExceptionData)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new ExceptionCore("error al intentar agregar el lote", ex);
     }
 }
        public async Task <IHttpActionResult> Put(LoteDto lotes)
        {
            if (category == null)
            {
                return(BadRequest(String.Format(Resources.RequestEmpty, _element)));
            }
            var principal = RequestContext.Principal as ClaimsPrincipal;

            category.UserModificatorId = principal.Identity.GetUserId();
            var res = this._servicio.Put(category).Result;

            switch (res)
            {
            case -1:
                return(BadRequest(String.Format(Resources.UpdateError, _element)));

            default:
                return(Ok(String.Format(Resources.UpdateOk, _element)));
            }
        }
        public async Task <IHttpActionResult> Post(LoteDto lotes)
        {
            if (category == null)
            {
                return(BadRequest(String.Format(Resources.RequestEmpty, _element)));
            }
            var principal = RequestContext.Principal as ClaimsPrincipal;

            category.UserCreatorId     = principal.Identity.GetUserId();
            category.UserModificatorId = principal.Identity.GetUserId();
            var res = this._servicio.Post(category).Result;

            if (res > 0)
            {
                return(Ok(String.Format(Resources.SaveOk, _element)));
            }
            else
            {
                return(BadRequest(String.Format(Resources.SaveError, _element)));
            }
        }