private void loadPicture(CMSDataContext cmsdb, CMSImageDataContext cmsidb, bool returnUrl) { var person = cmsdb.People.SingleOrDefault(p => p.PeopleId == id); int?ImageId; if (person == null || person.Picture == null) { if (returnUrl) { var pic = new CmsData.Picture(); picture = pic.MediumUrl; return; } ImageId = CmsData.Picture.SmallMissingGenericId; } else { pictureX = person.Picture.X.GetValueOrDefault(); pictureY = person.Picture.Y.GetValueOrDefault(); if (returnUrl) { switch (person?.Gender?.Code) { case "M": picture = person.Picture.MediumMaleUrl; break; case "F": picture = person.Picture.MediumFemaleUrl; break; default: picture = person.Picture.MediumUrl; break; } return; } ImageId = person.Picture.SmallId; } Image image = cmsidb.Images.SingleOrDefault(i => i.Id == ImageId); if (image != null) { picture = Convert.ToBase64String(image.Bits); } }
public ActionResult SaveImage(int id, string image) { var authError = Authenticate(); if (authError != null) return authError; BaseReturn br = new BaseReturn(); var imageBytes = Convert.FromBase64String(image); var person = DbUtil.Db.People.SingleOrDefault(pp => pp.PeopleId == id); if (person.Picture != null) { ImageData.DbUtil.Db.Images.DeleteOnSubmit(ImageData.DbUtil.Db.Images.Where(i => i.Id == person.Picture.ThumbId).SingleOrDefault()); ImageData.DbUtil.Db.Images.DeleteOnSubmit(ImageData.DbUtil.Db.Images.Where(i => i.Id == person.Picture.SmallId).SingleOrDefault()); ImageData.DbUtil.Db.Images.DeleteOnSubmit(ImageData.DbUtil.Db.Images.Where(i => i.Id == person.Picture.MediumId).SingleOrDefault()); ImageData.DbUtil.Db.Images.DeleteOnSubmit(ImageData.DbUtil.Db.Images.Where(i => i.Id == person.Picture.LargeId).SingleOrDefault()); person.Picture.ThumbId = ImageData.Image.NewImageFromBits(imageBytes, 50, 50).Id; person.Picture.SmallId = ImageData.Image.NewImageFromBits(imageBytes, 120, 120).Id; person.Picture.MediumId = ImageData.Image.NewImageFromBits(imageBytes, 320, 400).Id; person.Picture.LargeId = ImageData.Image.NewImageFromBits(imageBytes, 570, 800).Id; } else { var newPicture = new Picture(); newPicture.ThumbId = ImageData.Image.NewImageFromBits( imageBytes, 50, 50 ).Id; newPicture.SmallId = ImageData.Image.NewImageFromBits( imageBytes, 120, 120 ).Id; newPicture.MediumId = ImageData.Image.NewImageFromBits( imageBytes, 320, 400 ).Id; newPicture.LargeId = ImageData.Image.NewImageFromBits( imageBytes, 570, 800 ).Id; person.Picture = newPicture; } DbUtil.Db.SubmitChanges(); br.error = 0; br.data = "Image updated."; br.id = id; br.count = 1; return br; }
public ActionResult SaveImage(string data) { // Authenticate first var result = AuthenticateUser(); if (!result.IsValid) return AuthorizationError(result); BaseMessage dataIn = BaseMessage.createFromString(data); MobilePostSaveImage mpsi = JsonConvert.DeserializeObject<MobilePostSaveImage>(dataIn.data); BaseMessage br = new BaseMessage(); var imageBytes = Convert.FromBase64String(mpsi.image); var person = DbUtil.Db.People.SingleOrDefault(pp => pp.PeopleId == mpsi.id); if (person.Picture != null) { if (ImageData.DbUtil.Db.Images.SingleOrDefault(i => i.Id == person.Picture.ThumbId) != null) ImageData.DbUtil.Db.Images.DeleteOnSubmit(ImageData.DbUtil.Db.Images.SingleOrDefault(i => i.Id == person.Picture.ThumbId)); if (ImageData.DbUtil.Db.Images.SingleOrDefault(i => i.Id == person.Picture.ThumbId) != null) ImageData.DbUtil.Db.Images.DeleteOnSubmit(ImageData.DbUtil.Db.Images.SingleOrDefault(i => i.Id == person.Picture.SmallId)); if (ImageData.DbUtil.Db.Images.SingleOrDefault(i => i.Id == person.Picture.ThumbId) != null) ImageData.DbUtil.Db.Images.DeleteOnSubmit(ImageData.DbUtil.Db.Images.SingleOrDefault(i => i.Id == person.Picture.MediumId)); if (ImageData.DbUtil.Db.Images.SingleOrDefault(i => i.Id == person.Picture.ThumbId) != null) ImageData.DbUtil.Db.Images.DeleteOnSubmit(ImageData.DbUtil.Db.Images.SingleOrDefault(i => i.Id == person.Picture.LargeId)); person.Picture.ThumbId = Image.NewImageFromBits(imageBytes, 50, 50).Id; person.Picture.SmallId = Image.NewImageFromBits(imageBytes, 120, 120).Id; person.Picture.MediumId = Image.NewImageFromBits(imageBytes, 320, 400).Id; person.Picture.LargeId = Image.NewImageFromBits(imageBytes).Id; } else { var newPicture = new Picture(); newPicture.ThumbId = Image.NewImageFromBits(imageBytes, 50, 50).Id; newPicture.SmallId = Image.NewImageFromBits(imageBytes, 120, 120).Id; newPicture.MediumId = Image.NewImageFromBits(imageBytes, 320, 400).Id; newPicture.LargeId = Image.NewImageFromBits(imageBytes).Id; person.Picture = newPicture; } DbUtil.Db.SubmitChanges(); br.setNoError(); br.data = "Image updated."; br.id = mpsi.id; br.count = 1; return br; }
public void UploadPicture(CMSDataContext db, System.IO.Stream stream, int PeopleId) { if (Picture == null) Picture = new Picture(); var bits = new byte[stream.Length]; stream.Read(bits, 0, bits.Length); var p = Picture; p.CreatedDate = Util.Now; p.CreatedBy = Util.UserName; p.ThumbId = Image.NewImageFromBits(bits, 50, 50).Id; p.SmallId = Image.NewImageFromBits(bits, 120, 120).Id; p.MediumId = Image.NewImageFromBits(bits, 320, 400).Id; p.LargeId = Image.NewImageFromBits(bits).Id; LogPictureUpload(db, PeopleId, Util.UserPeopleId ?? 1); db.SubmitChanges(); }
public ActionResult SaveImage(string data) { // Authenticate first var authError = Authenticate(); if (authError != null) return authError; // Check to see if type matches BaseMessage dataIn = BaseMessage.createFromString(data); if (dataIn.type != BaseMessage.API_TYPE_PERSON_IMAGE_ADD) return BaseMessage.createTypeErrorReturn(); // Everything is in order, start the return MobilePostSaveImage mpsi = JsonConvert.DeserializeObject<MobilePostSaveImage>(dataIn.data); BaseMessage br = new BaseMessage(); var imageBytes = Convert.FromBase64String(mpsi.image); var person = DbUtil.Db.People.SingleOrDefault(pp => pp.PeopleId == mpsi.id); if (person.Picture != null) { ImageData.DbUtil.Db.Images.DeleteOnSubmit(ImageData.DbUtil.Db.Images.Where(i => i.Id == person.Picture.ThumbId).SingleOrDefault()); ImageData.DbUtil.Db.Images.DeleteOnSubmit(ImageData.DbUtil.Db.Images.Where(i => i.Id == person.Picture.SmallId).SingleOrDefault()); ImageData.DbUtil.Db.Images.DeleteOnSubmit(ImageData.DbUtil.Db.Images.Where(i => i.Id == person.Picture.MediumId).SingleOrDefault()); ImageData.DbUtil.Db.Images.DeleteOnSubmit(ImageData.DbUtil.Db.Images.Where(i => i.Id == person.Picture.LargeId).SingleOrDefault()); person.Picture.ThumbId = ImageData.Image.NewImageFromBits(imageBytes, 50, 50).Id; person.Picture.SmallId = ImageData.Image.NewImageFromBits(imageBytes, 120, 120).Id; person.Picture.MediumId = ImageData.Image.NewImageFromBits(imageBytes, 320, 400).Id; person.Picture.LargeId = ImageData.Image.NewImageFromBits(imageBytes).Id; } else { var newPicture = new Picture(); newPicture.ThumbId = ImageData.Image.NewImageFromBits(imageBytes, 50, 50).Id; newPicture.SmallId = ImageData.Image.NewImageFromBits(imageBytes, 120, 120).Id; newPicture.MediumId = ImageData.Image.NewImageFromBits(imageBytes, 320, 400).Id; newPicture.LargeId = ImageData.Image.NewImageFromBits(imageBytes).Id; person.Picture = newPicture; } DbUtil.Db.SubmitChanges(); br.error = 0; br.data = "Image updated."; br.id = mpsi.id; br.count = 1; return br; }
public ActionResult SaveImage(string data) { // Authenticate first if (!Auth()) return BaseMessage.createErrorReturn("Authentication failed, please try again", BaseMessage.API_ERROR_INVALID_CREDENTIALS); BaseMessage dataIn = BaseMessage.createFromString(data); CheckInSaveImage cisi = JsonConvert.DeserializeObject<CheckInSaveImage>(dataIn.data); BaseMessage br = new BaseMessage(); var imageBytes = Convert.FromBase64String(cisi.image); var person = DbUtil.Db.People.SingleOrDefault(pp => pp.PeopleId == cisi.id); if (person.Picture != null) { if (ImageData.DbUtil.Db.Images.SingleOrDefault(i => i.Id == person.Picture.ThumbId) != null) ImageData.DbUtil.Db.Images.DeleteOnSubmit(ImageData.DbUtil.Db.Images.SingleOrDefault(i => i.Id == person.Picture.ThumbId)); if (ImageData.DbUtil.Db.Images.SingleOrDefault(i => i.Id == person.Picture.ThumbId) != null) ImageData.DbUtil.Db.Images.DeleteOnSubmit(ImageData.DbUtil.Db.Images.SingleOrDefault(i => i.Id == person.Picture.SmallId)); if (ImageData.DbUtil.Db.Images.SingleOrDefault(i => i.Id == person.Picture.ThumbId) != null) ImageData.DbUtil.Db.Images.DeleteOnSubmit(ImageData.DbUtil.Db.Images.SingleOrDefault(i => i.Id == person.Picture.MediumId)); if (ImageData.DbUtil.Db.Images.SingleOrDefault(i => i.Id == person.Picture.ThumbId) != null) ImageData.DbUtil.Db.Images.DeleteOnSubmit(ImageData.DbUtil.Db.Images.SingleOrDefault(i => i.Id == person.Picture.LargeId)); person.Picture.ThumbId = ImageData.Image.NewImageFromBits(imageBytes, 50, 50).Id; person.Picture.SmallId = ImageData.Image.NewImageFromBits(imageBytes, 120, 120).Id; person.Picture.MediumId = ImageData.Image.NewImageFromBits(imageBytes, 320, 400).Id; person.Picture.LargeId = ImageData.Image.NewImageFromBits(imageBytes).Id; } else { var newPicture = new Picture(); newPicture.ThumbId = ImageData.Image.NewImageFromBits(imageBytes, 50, 50).Id; newPicture.SmallId = ImageData.Image.NewImageFromBits(imageBytes, 120, 120).Id; newPicture.MediumId = ImageData.Image.NewImageFromBits(imageBytes, 320, 400).Id; newPicture.LargeId = ImageData.Image.NewImageFromBits(imageBytes).Id; person.Picture = newPicture; } person.LogPictureUpload(DbUtil.Db, Util.UserPeopleId ?? 1); DbUtil.Db.SubmitChanges(); br.setNoError(); br.data = "Image updated"; br.id = cisi.id; br.count = 1; return br; }