Beispiel #1
0
        public async Task <ActionResult <UploadResultViewModel> > DeleteAsync(string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                return(BadRequest("No valid Url received"));
            }

            try
            {
                if (!Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute))
                {
                    return(UnprocessableEntity(new ErrorViewModel
                    {
                        Type = Type.Error, Message = "UrI not correctly formatted"
                    }));
                }

                Uri    uri               = new Uri(url);
                string blobfilename      = Path.GetFileName(uri.LocalPath);
                string blobContainerName = uri.AbsolutePath.Substring(1, uri.AbsolutePath.IndexOf('/', 1) - 1);
                bool   result            = await blobService.DeleteFileBlobAsync(blobContainerName, blobfilename);

                return(Ok(new UploadResultViewModel {
                    Succeeded = result
                }));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, GetType().Name + "Error in " + nameof(DeleteAsync));
                return(UnprocessableEntity(new UploadResultViewModel {
                    Succeeded = false
                }));
            }
        }
        /// <summary>
        /// call Save and update customer repository object
        /// </summary>
        /// <param name="customerObject"></param>
        /// <returns></returns>
        public Task <ServiceResponse> SaveCustomer(Customers customerObject)
        {
            try
            {
                var customerDataMapperWrapper = new CustomerDataMapperWrapper {
                    customer = customerObject
                };

                if (!_customerCreateValidator.Validate(customerDataMapperWrapper, out IList <Message> messages))
                {
                    return(Task.FromResult(_serviceResponseErrorMapper.Map(messages)));
                }

                var saveObject = _customerDataMapper.Map(customerDataMapperWrapper);

                if (saveObject.Id > 0)
                {
                    if (saveObject.File != null)
                    {
                        _blobService.DeleteFileBlobAsync(saveObject.ImageName);
                        var imageObject = _blobService.UploadProfilePicture(saveObject.File);
                        saveObject.ImageUrl  = imageObject.Result.Item1;
                        saveObject.ImageName = imageObject.Result.Item2;
                    }
                    return(Task.FromResult(_serviceResponseMapper.Map(_customerRepository.UpdateCustomer(saveObject))));
                }
                else
                {
                    var imageObject = _blobService.UploadProfilePicture(saveObject.File);
                    saveObject.ImageUrl  = imageObject.Result.Item1;
                    saveObject.ImageName = imageObject.Result.Item2;
                    return(Task.FromResult(_serviceResponseMapper.Map(_customerRepository.CreateCustomer(saveObject))));
                }
            }
            catch
            {
                throw;
            }
        }
Beispiel #3
0
        public async Task <IActionResult> DeleteFile(string fileName)
        {
            var result = await _blobService.DeleteFileBlobAsync("firstcontainer", fileName);

            return(Ok());
        }
        public async Task <ActionResult> DeleteBlob(string blobName)
        {
            await _blobService.DeleteFileBlobAsync(blobName);

            return(Ok());
        }