Ejemplo n.º 1
0
        public async Task <TransactionResult> SaveImageTransaction(ProjectPhotoDTO projectPhotoDTO, string user)
        {
            try
            {
                AspNetUsers _user = await context.AspNetUsers.Where(u => u.UserName == user).FirstOrDefaultAsync();

                Project _project = null;
                if (projectPhotoDTO.Id != null)
                {
                    _project = await context.Project.FindAsync(projectPhotoDTO.Id);
                }
                if (_project != null)
                {
                    if (_project.AspNetUsers != _user)
                    {
                        return(new TransactionResult(TransResult.Fail, "This is not your project", null));
                    }
                }
                var projectPhoto = new ProjectPhoto
                {
                    Project1 = _project,
                    Photo    = Convert.FromBase64String(projectPhotoDTO.PhotoString)
                };
                context.ProjectPhoto.Add(projectPhoto);
                await context.SaveChangesAsync();

                return(new TransactionResult(TransResult.Success, "Success", null));
            }
            catch (Exception ex) { return(new TransactionResult(TransResult.Fail, ex.Message, ex)); }
        }
Ejemplo n.º 2
0
        public async Task <TransactionResult> ReadProjectMainImage(int id, int?pointer = null)
        {
            try
            {
                Project project = await context.Project.FindAsync(id);

                var photo = await context.ProjectPhoto.FindAsync(project.MainPhotoFK);

                var result = new ProjectPhotoDTO
                {
                    Id        = photo.Id,
                    Photo     = photo.Photo,
                    ProjectFK = project.Id,
                    Pointer   = pointer
                };
                return(new TransactionResult(TransResult.Success, string.Empty, result));
            }
            catch (Exception ex) { return(new TransactionResult(TransResult.Fail, ex.Message, ex)); }
        }