public static FileContentResult GetImage(Guid imageGuid, bool isThumb = true, int width = 50, int height = 50) { byte[] byteArray = GetFromLocalStorage(imageGuid, isThumb, width, height); if (byteArray != null) { return(new FileContentResult(byteArray, "image/png")); } var image = _wcfService.InvokeService <IVirtueContextService, Image>(svc => svc.GetImage(imageGuid)); if (image != null) { if (isThumb) { using (var ms = new MemoryStream()) { using ( var thumbnail = MsImage.FromStream(new MemoryStream(image.Context)) .GetThumbnailImage(width, height, null, new IntPtr())) { thumbnail.Save(ms, ImageFormat.Png); byteArray = ms.ToArray(); } } SaveToLocalStorage(byteArray, true, imageGuid, width, height); return(new FileContentResult(byteArray, "image/png")); } SaveToLocalStorage(image.Context, false, imageGuid, width, height); return(new FileContentResult(image.Context, image.Extension)); } return(null); }
public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid) { try { var user = _wcfService.InvokeService <IVirtueSecurityService, User>( (svc) => svc.GetUserByUserNameOrEmail(model.UserName, model.UserName)); if (user == null) { throw new Exception("Invalid User Name"); } var hashedPassword = _wcfService.InvokeService <IVirtueSecurityService, string>( (svc) => svc.CreatePasswordHash(model.Password, user.Salt)); if (hashedPassword.Equals(user.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false); SetUserIdentity(user); if (!HttpContext.User.IsInRole(Constants.SysAdminRole)) { FormsAuthentication.SignOut(); throw new SecurityException("Invalid user role. Access denied"); } if (Url.IsLocalUrl(returnUrl)) { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Home")); } } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult GetHomeTypes() { var model = _wcfService.InvokeService <IVirtueContextService, ICollection <HomeType> >((svc) => svc.GetHomeTypes(true)); return(PartialView("_HomeTypes", model.OrderBy(i => i.SortOrder))); }