示例#1
0
        public void ChangeFoto(FotoDTO editedFoto)
        {
            if (editedFoto == null || editedFoto.Link == null)
            {
                throw new ValidationException("Null foto input", "null");
            }

            try
            {
                var fotoToEdit = GetFoto(editedFoto.Id);
                var newFoto    = new Foto()
                {
                    Id          = editedFoto.Id,
                    Link        = editedFoto.Link,
                    Name        = editedFoto.Name,
                    UserOwnerId = fotoToEdit.UserOwnerId
                };
                foreach (var userDTO in fotoToEdit.UsersWithLike)
                {
                    var user = _dataBase.Users.Get(userDTO.Id);
                    newFoto.UsersWithLike.Add(user);
                }
                _dataBase.Fotos.Update(newFoto);
                _dataBase.Save();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw new ValidationException("Error while uploading foto", "");
            }
        }
示例#2
0
        public async Task <IActionResult> Upload(List <IFormFile> files, int IdSesion)
        {
            try
            {
                var dtoList = new List <FotoDTO>();

                foreach (IFormFile file in files)
                {
                    var dto = new FotoDTO();
                    dto.Nombre = file.FileName;
                    dto.Path   = Path.GetTempFileName();

                    using (var stream = new FileStream(dto.Path, FileMode.Create))
                    {
                        await file.CopyToAsync(stream);
                    }

                    dtoList.Add(dto);
                }

                await _serviceFoto.UploadFotos(dtoList, IdSesion);

                return(Json(new { success = true }));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false }));
            }
        }
 public IHttpActionResult GetFoto(int id)
 {
     try
     {
         FotoDTO fotoDTO = travelService.GetFoto(id);
         Mapper.Initialize(cfg => cfg.CreateMap <FotoDTO, FotoViewModel>());
         var foto = Mapper.Map <FotoDTO, FotoViewModel>(fotoDTO);
         return(Ok(foto));
     }
     catch (ValidationException ex)
     {
         return(Content(HttpStatusCode.BadRequest, ex.Message));
     }
 }
示例#4
0
        public void UploadFoto(FotoDTO foto)
        {
            if (foto == null || foto.Link == null)
            {
                throw new ValidationException("Null foto input", "null");
            }

            var user = _dataBase.Users.Get(foto.UserOwnerId);

            if (user == null)
            {
                throw new ValidationException("User not found", "null");
            }

            try
            {
                var newFoto = new Foto()
                {
                    Link        = foto.Link,
                    Name        = foto.Name,
                    UserOwnerId = foto.UserOwnerId
                };
                foreach (var userDTO in foto.UsersWithLike)
                {
                    var bufUser = _dataBase.Users.Get(userDTO.Id);
                    newFoto.UsersWithLike.Add(bufUser);
                }
                _dataBase.Fotos.Create(newFoto);
                user.Fotos.Add(newFoto);
                _dataBase.Save();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw new ValidationException("Error while uploading foto", "");
            }
        }
示例#5
0
 public FotoDetailViewModel(FotoDTO foto)
 {
     FotoAtual = foto;
 }
示例#6
0
 // PUT api/values/5
 public IHttpActionResult Put(int id, [FromBody] FotoDTO data)
 {
     _service.ChangeFoto(data);
     return(Ok());
 }
示例#7
0
 // POST api/values
 public IHttpActionResult Post([FromBody] FotoDTO data)
 {
     _service.UploadFoto(data);
     return(Ok());
 }
 public FotoDetailView(FotoDTO foto)
 {
     InitializeComponent();
     BindingContext = new FotoDetailViewModel(foto);
 }