public HttpResponseMessage Get(int id) { ServiceData.Models.UserCondition found = _conditionRepository.GetById(id); if (found == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } if (found.Owner.Email != User.Identity.Name) { return(Request.CreateResponse(HttpStatusCode.Forbidden)); } if (found.Photos.Count() > 0) { found.Photos = found.Photos.OrderByDescending(photo => photo.CreatedAt); } Models.UserCondition toRet = Models.UserCondition.ToAppModel(found, false); ServerUtils.LogTelemetryEvent(User.Identity.Name, "GetCondition"); PostLog("UserConditions_GetSingle", found.Owner.Id); return(Request.CreateResponse(HttpStatusCode.OK, toRet)); }
public HttpResponseMessage Get(int id) { ServiceData.Models.Photo found = _photoRepository.GetById(id); if (found == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } if (!IsSameUser(found)) { return(Request.CreateResponse(HttpStatusCode.Forbidden)); } Models.Photo toRet = Models.Photo.ToAppModel(found, false); ServerUtils.LogTelemetryEvent(User.Identity.Name, "GetPhoto"); PostLog("Photos_GetSingle"); return(Request.CreateResponse(HttpStatusCode.OK, toRet)); }
public async Task <HttpResponseMessage> Get(string imageId, bool thumb = false) { int id; if (string.IsNullOrEmpty(imageId) || !Int32.TryParse(imageId, out id)) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } ServiceData.Models.Photo found = _photoRepository.GetById(id); if (found == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } ServiceData.Models.UserCondition foundCond = _conditionRepository.GetById(found.UserCondition.Id); if (foundCond.Owner.Email != User.Identity.Name) { return(Request.CreateResponse(HttpStatusCode.Forbidden)); } string target = (thumb) ? found.ThumbUrl : found.Url; CloudBlobContainer container = await GetBlobContainer(); Stream blobStream = new MemoryStream(); CloudBlob photoBlob = container.GetBlobReference(target.Replace(ConfidentialData.BlobStorageUrl, "")); KeyVaultKeyResolver cloudResolver = new KeyVaultKeyResolver(ServerUtils.GetToken); IKey rsa = await cloudResolver.ResolveKeyAsync(ConfidentialData.KeyLocation, CancellationToken.None); BlobEncryptionPolicy policy = new BlobEncryptionPolicy(null, cloudResolver); BlobRequestOptions options = new BlobRequestOptions() { EncryptionPolicy = policy }; await photoBlob.DownloadToStreamAsync(blobStream, null, options, null); blobStream.Position = 0; HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StreamContent(blobStream); response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment"); response.Content.Headers.ContentDisposition.FileName = imageId + Path.GetExtension(target); string eventName = thumb ? "DownloadThumb" : "DownloadImage"; ServerUtils.LogTelemetryEvent(User.Identity.Name, eventName); return(response); }
public async Task <HttpResponseMessage> Delete(int id) { ServiceData.Models.Share found = _shareRepository.GetById(id); if (found == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } if (found.Owner.Email != User.Identity.Name) { return(Request.CreateResponse(HttpStatusCode.Forbidden)); } await _shareRepository.Delete(id); ServerUtils.LogTelemetryEvent(User.Identity.Name, "DeleteShare"); return(Request.CreateResponse(HttpStatusCode.OK)); }
public static async Task Delete(IReadWriteRepository <ServiceData.Models.UserCondition> conditionRep, IReadWriteRepository <ServiceData.Models.Share> shareRep, IReadWriteRepository <ServiceData.Models.Photo> photoRep, int id) { ServiceData.Models.UserCondition found = conditionRep.GetById(id); if (found == null) { return; } ServiceData.Models.Share[] foundShares = shareRep.Search(sh => sh.UserCondition.Id == found.Id).ToArray(); foreach (ServiceData.Models.Share share in foundShares) { await shareRep.Delete(share.Id); } CloudBlobContainer container = await UploadController.GetBlobContainer(); foreach (ServiceData.Models.Photo photo in found.Photos) { await PhotoController.Delete(photoRep, photo.Id); } await conditionRep.Delete(id); }
public static async Task Delete(IReadWriteRepository <ServiceData.Models.Photo> photoRep, int id) { ServiceData.Models.Photo found = photoRep.GetById(id); CloudBlobContainer container = await UploadController.GetBlobContainer(); try { string url = UploadController.GetFilePathFromUrl(found.Url); var mainBlob = container.GetBlockBlobReference(url); mainBlob.Delete(); } catch { } try { string thumbUrl = UploadController.GetFilePathFromUrl(found.ThumbUrl); var thumbBlob = container.GetBlockBlobReference(thumbUrl); thumbBlob.Delete(); } catch { } await photoRep.Delete(id); }
// GET api/values/5 public HttpResponseMessage Get(int id) { ServiceData.Models.User found = _userRepository.GetById(id); if (found == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } if (found.Email != User.Identity.Name) { return(Request.CreateResponse(HttpStatusCode.Forbidden)); } Models.User toRet = Models.User.ToAppModel(found); if (toRet.BirthDate == null || (DateTime.UtcNow - toRet.BirthDate).TotalDays < 2) { toRet.BirthDate = DateTime.UtcNow.AddYears(-30); } ServerUtils.LogTelemetryEvent(User.Identity.Name, "GetUser"); PostLog("Users_GetSingle", found.Id); return(Request.CreateResponse(HttpStatusCode.OK, toRet)); }
public Rant GetRantById(int rantId) { return(_readWriteRepository.GetById(rantId)); }
public Production Get(Guid id) { return(_productionRepository.GetById(id)); }
public async Task <HttpResponseMessage> Get() { try { string[] testUsers = new string[] { "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**" }; string baseFileLoc = "C:/Users/tgs03_000/Downloads/SkinSelfies"; //if (Directory.Exists(baseFileLoc)) //{ // Directory.Delete(baseFileLoc, true); //} if (!Directory.Exists(baseFileLoc)) { Directory.CreateDirectory(baseFileLoc); } List <Task> allTasks = new List <Task>(); List <string> nullEmails = new List <string>(); foreach (string userEmail in testUsers) { ServiceData.Models.User user = _userRepository.Search(u => u.Email == userEmail).FirstOrDefault(); DirectoryInfo userDir = Directory.CreateDirectory(Path.Combine(baseFileLoc, userEmail)); if (user == null) { nullEmails.Add(userEmail); continue; } AboutUser userDetails = new AboutUser { Id = user.Id, Email = user.Email, Name = user.Name, Dob = user.BirthDate }; File.WriteAllText(Path.Combine(userDir.FullName, "AboutUser.txt"), JsonConvert.SerializeObject(userDetails, Formatting.Indented)); foreach (ServiceData.Models.UserCondition cond in user.Conditions) { ServiceData.Models.UserCondition fullCond = _conditionRepository.GetById(cond.Id); string condPath = Path.Combine(userDir.FullName, cond.Id.ToString()); DirectoryInfo condDir = Directory.Exists(condPath)? new DirectoryInfo(condPath) : Directory.CreateDirectory(condPath); AboutCondition condDetails = new AboutCondition { Id = user.Id, Name = cond.Condition, SkinRegion = fullCond.SkinRegion.BodyPart.Name + " - " + fullCond.SkinRegion.Name, StartDate = cond.StartDate, NumPhotos = fullCond.Photos.Count() }; File.WriteAllText(Path.Combine(condDir.FullName, "AboutCondition.txt"), JsonConvert.SerializeObject(condDetails, Formatting.Indented)); foreach (ServiceData.Models.Photo photo in fullCond.Photos) { string filename = Path.Combine(condDir.FullName, photo.CreatedAt.ToString("yyyy-MM-dd-HH-mm-ss.") + Path.GetExtension(photo.Url)); if (File.Exists(filename)) { continue; } CloudBlobContainer container = await GetBlobContainer(); Stream blobStream = new MemoryStream(); CloudBlob photoBlob = container.GetBlobReference(photo.Url.Replace(ConfidentialData.BlobStorageUrl, "")); KeyVaultKeyResolver cloudResolver = new KeyVaultKeyResolver(ServerUtils.GetToken); IKey rsa = await cloudResolver.ResolveKeyAsync(ConfidentialData.KeyLocation, CancellationToken.None); BlobEncryptionPolicy policy = new BlobEncryptionPolicy(null, cloudResolver); BlobRequestOptions options = new BlobRequestOptions() { EncryptionPolicy = policy }; await photoBlob.DownloadToStreamAsync(blobStream, null, options, null); blobStream.Position = 0; using (var fileStream = File.Create(filename)) { await blobStream.CopyToAsync(fileStream); } } } } string nullString = ""; foreach (string nEmail in nullEmails) { nullString += nEmail + ", "; } return(Request.CreateResponse(HttpStatusCode.OK, "Files located at " + baseFileLoc + " Null emails: " + nullString)); } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e)); } }