public async Task <DefaultResponseModel> AddCreditCardAsync(string token, CreditCardData creditCardData) { DefaultResponseModel response = new DefaultResponseModel { IsSuccessful = false, Message = string.Empty }; ClientData client = await sessionHandler.GetClientAsync(token); if (client == null) { response.Message = "Unauthorized user"; return(response); } CreditCardData cardInDatabase = await creditCardRepository.GetByNumberAsync(creditCardData.Number); if (cardInDatabase != null) { response.Message = "This card already registered in the database"; return(response); } creditCardData.ClientId = client.Id; creditCardData = await creditCardRepository.AddAsync(creditCardData); if (creditCardData.Id > 0) { response.IsSuccessful = true; } return(response); }
public async Task <UpdateImageResponseModel> UpdateProfileImageAsync(UpdateProfileImageModel updateProfileImageModel) { var response = new UpdateImageResponseModel { IsSuccessful = false, Message = "Error while updating" }; ClientData client = await sessionHandler.GetClientAsync(updateProfileImageModel.Token); if (client == null) { response.Message = "Invalid javascript web token - access denied"; return(response); } try { string clientImageFolderAbsolutePath = Path.Combine(Directory.GetCurrentDirectory(), webFilesFolder, accountImageStorage, client.Id.ToString()); if (!Directory.Exists(clientImageFolderAbsolutePath)) { Directory.CreateDirectory(clientImageFolderAbsolutePath); } string newImageRelativePath = Path.Combine(accountImageStorage, client.Id.ToString(), updateProfileImageModel.Image.FileName); string newImageAbsolutePath = Path.Combine(clientImageFolderAbsolutePath, updateProfileImageModel.Image.FileName); if (updateProfileImageModel.Image.Length <= 0) { response.Message = "Error while loading file"; return(response); } using (var stream = new FileStream(newImageAbsolutePath, FileMode.Create)) { await updateProfileImageModel.Image.CopyToAsync(stream); } string oldImageAbsolutePath = Path.Combine(Directory.GetCurrentDirectory(), webFilesFolder, client.PhotoPath); if (File.Exists(oldImageAbsolutePath) && (oldImageAbsolutePath != newImageAbsolutePath)) { File.Delete(oldImageAbsolutePath); } client.PhotoPath = newImageRelativePath; await clientRepository.UpdateAsync(client); response.IsSuccessful = true; response.Message = newImageRelativePath; return(response); } catch (Exception) { return(response); } }