public async Task <HttpResponseMessage> DeleteItem([FromUri] CustomerFileDeleteRequest request) { HttpResponseMessage httpResponse = null; string uri = Url.Link("CustomerDeleteItemApi", new { id = request.id }); string userId = request.userName; IResultModel response = new ResultModel(); if (request.id <= 0) { response.OnError(CustomerResources.ErrorItemDoesNotExist_OnDelete, EnumErrorCode.ITEM_DOES_NOT_EXIST); } else { try { var rmCred = this.ValidateUserCredentials(request.userName); if (rmCred.Success) { response = await this.customerService.DeleteFileAsync(request); } else { response.OnError(rmCred.ErrorMessage, rmCred.ErrorCode); } } catch (Exception ex) { response.OnException(ex); } } httpResponse = Request.CreateResponse <IResultModel>(HttpStatusCode.Created, response); httpResponse.Headers.Location = new Uri(uri); return(httpResponse); }
public async Task <IResultModel> DeleteFileAsync(CustomerFileDeleteRequest request) { IResultModel rm = new ResultModel(); string customerId = string.Empty, channelId = string.Empty; try { var rmGet = this.fileRepository.Find(request.id); if (rmGet.Success) { var item = rmGet.Value; customerId = item.CustomerId.ToString(); channelId = item.ChannelId.ToString(); if (item.Customer.Email == request.userName) { this.fileRepository.Remove(item); var rmDelete = await this.fileRepository.SaveAsync(); if (rmDelete.Success) { //Elimina los archivos string[] folders = new string[] { UploadFoldersEnum.CustomerFiles.ToString(), customerId, channelId }; var rmDeleteFiles = this.fileService.DeleteFolderPhysicalPath(folders); if (rmDeleteFiles.Success) { rm.OnSuccess(); } else { rm.OnError(rmDeleteFiles.ErrorMessage, rmDeleteFiles.ErrorCode); } } else { rm.OnError(rmDelete.ErrorMessage, rmDelete.ErrorCode); } } else { rm.OnError(CustomerResources.ErrorItemDoesNotExist_OnDelete); } } else { rm.OnError(rmGet.ErrorMessage, rmGet.ErrorCode); } } catch (Exception ex) { rm.OnException(ex); } return(rm); }
public IResultModel DeleteFile(CustomerFileDeleteRequest request) { return(this.asyncService.RunSync(() => this.DeleteFileAsync(request))); }