public JsonResult UploadImage() { JsonResponse response = new JsonResponse(); response.Message = ConstantUtil.MessageError; response.Status = ConstantUtil.StatusFail; try { string preImage = Request.Form["Image"].ToString(); HttpPostedFileBase file = Request.Files[0]; if (file != null && file.ContentLength > 0) { string relativePath = TempPath; var path = GetTargetPath(relativePath, file); System.Drawing.Image streamingImage = System.Drawing.Image.FromStream(file.InputStream); Bitmap img = new Bitmap(streamingImage); ImageUtility.ResizeandSaveImage(img, 25, 25, 100, path); DeleteFile(CompanyImagesPath, preImage); var spath = UrlUtility.GetAbsoluteUrl(relativePath + path.Split('\\').Last()); response.Status = ConstantUtil.StatusOk; response.ReturnUrl = spath; return(Json(response, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { logging.Error(ex.ToString()); } return(Json(response, JsonRequestBehavior.AllowGet)); }
public JsonResult UploadImage() { var response = new JsonResponse { Message = ConstantUtil.MessageError, Status = ConstantUtil.StatusFail }; try { const string relativePath = NotificationImagePath; HttpPostedFileBase file = Request.Files[0]; if (file != null && file.ContentLength > 0) { var path = GetTargetPath(relativePath, file); file.SaveAs(path); //TODO: remove unneded files response.Status = ConstantUtil.StatusOk; response.ReturnUrl = UrlUtility.GetAbsoluteUrl(relativePath + path.Split('\\').Last()); return(Json(response, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { logging.Error(ex.ToString()); } return(Json(response, JsonRequestBehavior.AllowGet)); }
public void GetPermanentUrlWithParentPermanentUrlAndRemoveInnermostReturnUrl() { string parameterName = "Param"; string parameterValue = "123456789 123456789 123456789 123456789 "; NameValueCollection queryString = new NameValueCollection(); queryString.Add(parameterName, parameterValue); NameValueCollection expectedQueryString = new NameValueCollection(); expectedQueryString.Add(queryString); string parentUrl = _currentHttpContext.Request.Url.AbsolutePath; parentUrl += UrlUtility.FormatQueryString(_currentHttpContext.Request.QueryString); parentUrl = UrlUtility.DeleteParameter(parentUrl, WxeHandler.Parameters.ReturnUrl); expectedQueryString.Add(WxeHandler.Parameters.ReturnUrl, parentUrl); string expectedUrl = UrlUtility.GetAbsoluteUrl(new HttpContextWrapper(_currentHttpContext), _resource); expectedUrl += UrlUtility.FormatQueryString(expectedQueryString); string permanentUrl = _currentWxeContext.GetPermanentUrl(_functionType, queryString, true); Assert.That(permanentUrl, Is.Not.Null); Assert.That(permanentUrl, Is.EqualTo(expectedUrl)); }
public void GetPermanentUrlWithEmptyQueryString() { string expectedUrl = UrlUtility.GetAbsoluteUrl(new HttpContextWrapper(_currentHttpContext), _resource); string permanentUrl = _currentWxeContext.GetPermanentUrl(_functionType, new NameValueCollection(), false); Assert.That(permanentUrl, Is.Not.Null); Assert.That(permanentUrl, Is.EqualTo(expectedUrl)); }
public void GetStaticPermanentUrlWithDefaultWxeHandlerForMappedFunctionType() { WebConfigurationMock.Current = WebConfigurationFactory.GetExecutionEngineWithDefaultWxeHandler(); string expectedUrl = UrlUtility.GetAbsoluteUrl(new HttpContextWrapper(_currentHttpContext), _resource); string permanentUrl = WxeContext.GetPermanentUrl(new HttpContextWrapper(_currentHttpContext), _functionType, new NameValueCollection()); Assert.That(permanentUrl, Is.Not.Null); Assert.That(permanentUrl, Is.EqualTo(expectedUrl)); }
public void ProcessRequest(HttpContext context) { string target = context.Request.QueryString["RedirectTo"]; if (string.IsNullOrEmpty(target)) { throw new InvalidOperationException("Url-Parameter 'RedirectTo' is missing."); } context.Response.Redirect(UrlUtility.GetAbsoluteUrl(new HttpContextWrapper(context), target)); }
public void GetStaticPermanentUrlWithDefaultWxeHandlerWithoutMappingForFunctionType() { WebConfigurationMock.Current = WebConfigurationFactory.GetExecutionEngineWithDefaultWxeHandler(); Remotion.Web.ExecutionEngine.UrlMapping.UrlMappingConfiguration.SetCurrent(null); string wxeHandler = Remotion.Web.Configuration.WebConfiguration.Current.ExecutionEngine.DefaultWxeHandler; string expectedUrl = UrlUtility.GetAbsoluteUrl(new HttpContextWrapper(_currentHttpContext), wxeHandler); NameValueCollection expectedQueryString = new NameValueCollection(); expectedQueryString.Add(WxeHandler.Parameters.WxeFunctionType, _functionTypeName); expectedUrl += UrlUtility.FormatQueryString(expectedQueryString); string permanentUrl = WxeContext.GetPermanentUrl(new HttpContextWrapper(_currentHttpContext), _functionType, new NameValueCollection()); Assert.That(permanentUrl, Is.Not.Null); Assert.That(permanentUrl, Is.EqualTo(expectedUrl)); }
/// <summary> /// Creates an <see cref="IconProxy"/> from an <see cref="IconInfo"/>. /// </summary> /// <param name="httpContext">The <see cref="HttpContext"/> of the current request. Used for resolving the URL. Must not be <see langword="null" />.</param> /// <param name="iconInfo">The <see cref="IconInfo"/> to be converted into an <see cref="IconProxy"/>. Must not be <see langword="null" />.</param> /// <returns>An <see cref="IconProxy"/> representing the <paramref name="iconInfo"/> in a web service interface. </returns> /// <exception cref="ArgumentException">Thrown if the <see cref="IconInfo.Url"/> of the <paramref name="iconInfo"/> is not set.</exception> public static IconProxy Create(HttpContextBase httpContext, IconInfo iconInfo) { ArgumentUtility.CheckNotNull("httpContext", httpContext); ArgumentUtility.CheckNotNull("iconInfo", iconInfo); if (string.IsNullOrEmpty(iconInfo.Url)) { throw new ArgumentException("IconProxy does not support IconInfo objects without an empty Url.", "iconInfo"); } var absoluteUrl = UrlUtility.GetAbsoluteUrl(httpContext, iconInfo.Url); return(new IconProxy( absoluteUrl, StringUtility.EmptyToNull(iconInfo.AlternateText), StringUtility.EmptyToNull(iconInfo.ToolTip), StringUtility.EmptyToNull(iconInfo.Height.ToString()), StringUtility.EmptyToNull(iconInfo.Width.ToString()))); }
public void GetPermanentUrlWithQueryString() { string parameterName = "Param"; string parameterValue = "Hello World!"; NameValueCollection queryString = new NameValueCollection(); queryString.Add(parameterName, parameterValue); NameValueCollection expectedQueryString = new NameValueCollection(); expectedQueryString.Add(queryString); string expectedUrl = UrlUtility.GetAbsoluteUrl(new HttpContextWrapper(_currentHttpContext), _resource); expectedUrl += UrlUtility.FormatQueryString(expectedQueryString); string permanentUrl = _currentWxeContext.GetPermanentUrl(_functionType, queryString, false); Assert.That(permanentUrl, Is.Not.Null); Assert.That(permanentUrl, Is.EqualTo(expectedUrl)); }
/// <summary> Gets the absolute path that resumes the function with specified token. </summary> /// <param name="path"> The path to the <see cref="WxeHandler"/>. Must not be <see langword="null"/> or emtpy. </param> /// <param name="functionToken"> /// The function token of the function to resume. Must not be <see langword="null"/> or emtpy. /// </param> /// <param name="queryString"> An optional list of URL parameters to be appended to the <paramref name="path"/>. </param> private string GetPath(string path, string functionToken, NameValueCollection queryString) { ArgumentUtility.CheckNotNullOrEmpty("path", path); ArgumentUtility.CheckNotNullOrEmpty("functionToken", functionToken); if (path.IndexOf("?") != -1) { throw new ArgumentException("The path must be provided without a query string. Use the query string parameter instead.", "path"); } if (queryString == null) { queryString = new NameValueCollection(); } else { queryString = NameValueCollectionUtility.Clone(queryString); } queryString.Set(WxeHandler.Parameters.WxeFunctionToken, functionToken); path = UrlUtility.GetAbsoluteUrl(_httpContext, path); return(UrlUtility.AddParameters(path, queryString, _httpContext.Response.ContentEncoding)); }
public ActionResult Edit(Company model, long?id) { ViewData["pagename"] = "company"; JsonResponse response = new JsonResponse(); response.Message = ConstantUtil.MessageError; response.Status = ConstantUtil.StatusFail; if (ModelState.IsValid) { try { if (!string.IsNullOrEmpty(model.Image) && !System.IO.File.Exists(Server.MapPath(CompanyImagesPath) + model.Image.Split('/').Last()) && System.IO.File.Exists(Server.MapPath(TempPath) + model.Image.Split('/').Last())) { System.IO.File.Copy(Server.MapPath(TempPath) + model.Image.Split('/').Last(), Server.MapPath(CompanyImagesPath) + model.Image.Split('/').Last()); model.Image = UrlUtility.GetAbsoluteUrl(CompanyImagesPath + model.Image.Split('/').Last()); } model.ModifiedBy = CurrentUser; model.ModifiedDate = DateTime.UtcNow; var companyEntity = _companyService.Find(model.CompanyId); companyEntity.CompanyName = model.CompanyName; companyEntity.ContactPerson = model.ContactPerson; companyEntity.Address1 = model.Address1; companyEntity.Address2 = model.Address2; companyEntity.State = model.State; companyEntity.City = model.City; companyEntity.Zip = model.Zip; companyEntity.CountryID = model.CountryID; companyEntity.Phone = model.Phone; companyEntity.Email = model.Email; companyEntity.Active = model.Active; companyEntity.CreatedDate = DateTime.UtcNow; companyEntity.ModifiedBy = model.ModifiedBy; companyEntity.ModifiedDate = DateTime.UtcNow; companyEntity.Image = model.Image; companyEntity.VuforiaServerAccessKey = model.VuforiaServerAccessKey; companyEntity.VuforiaServerSecretKey = model.VuforiaServerSecretKey; companyEntity.VuforiaClientAccessKey = model.VuforiaClientAccessKey; companyEntity.VuforiaClientSecretKey = model.VuforiaClientSecretKey; companyEntity.ObjectState = ObjectState.Modified; _companyService.Update(companyEntity); bool success = _unitOfWorkAsync.SaveChanges() > 0; if (success) { logging.Info("Company updated with name " + model.CompanyName); response.Message = "Company updated successfully"; response.Status = ConstantUtil.StatusOk; response.ReturnUrl = Url.Action("Index"); } } catch (Exception ex) { logging.Error(ex.ToString()); } } return(Json(response, JsonRequestBehavior.AllowGet)); }
public ActionResult Create(Company model) { JsonResponse response = new JsonResponse(); response.Message = ConstantUtil.MessageError; response.Status = ConstantUtil.StatusFail; ViewData["pagename"] = "company"; if (ModelState.IsValid) { try { model.Active = true; if (_userService.IsUserExist(model.Email)) { response.Message = ConstantUtil.UaernameExist; } else { if (!string.IsNullOrEmpty(model.Image) && !System.IO.File.Exists(Server.MapPath(CompanyImagesPath) + model.Image.Split('/').Last()) && System.IO.File.Exists(Server.MapPath(TempPath) + model.Image.Split('/').Last())) { System.IO.File.Copy(Server.MapPath(TempPath) + model.Image.Split('/').Last(), Server.MapPath(CompanyImagesPath) + model.Image.Split('/').Last()); model.Image = UrlUtility.GetAbsoluteUrl(CompanyImagesPath + model.Image.Split('/').Last()); } string password = model.Password; model.Password = EncryptionHelper.Encrypt(model.Password); model.CreatedBy = CurrentUser; model.CreatedDate = DateTime.UtcNow; model.Active = true; model.RoleId = 2; //bool success = _company.CreateCompany(model); var companyAdmin = new LiveKart.Entities.User() { UserName = model.UserName, Email = model.Email, Password = model.Password, RoleType = model.RoleId.GetValueOrDefault(2), CreatedDate = DateTime.UtcNow, }; var companyEntity = new LiveKart.Entities.Company() { CompanyId = model.CompanyId, CompanyName = model.CompanyName, ContactPerson = model.ContactPerson, Address1 = model.Address1, Address2 = model.Address2, State = model.State, City = model.City, Zip = model.Zip, CountryID = model.CountryID, Phone = model.Phone, Email = model.Email, UserName = model.UserName, Active = model.Active, CreatedBy = model.CreatedBy, CreatedDate = DateTime.UtcNow, ModifiedBy = model.ModifiedBy, ModifiedDate = DateTime.UtcNow, Image = model.Image, VuforiaServerAccessKey = model.VuforiaServerAccessKey, VuforiaServerSecretKey = model.VuforiaServerSecretKey, VuforiaClientAccessKey = model.VuforiaClientAccessKey, VuforiaClientSecretKey = model.VuforiaClientSecretKey, User = companyAdmin, }; _unitOfWorkAsync.Repository <LiveKart.Entities.User>().Insert(companyAdmin); _unitOfWorkAsync.Repository <LiveKart.Entities.Company>().Insert(companyEntity); int saveResult = _unitOfWorkAsync.SaveChanges(); bool success = saveResult >= 0; if (success) { response.Message = "Company created successfully but Password sending failed."; response.Status = ConstantUtil.StatusOk; response.ReturnUrl = Url.Action("Index"); logging.Info("New company created with name " + model.CompanyName); string appUrl = Business.UrlUtility.GetApplicationUrl(); string emailbody = "<html xmlns='http://www.w3.org/1999/xhtml'><head><title></title></head><body><h3><i>Greetings!</i></h3>" + "<p>Thank you for registering your account with us.</p><p>Your AR user name is: " + model.Email + " </p>" + "<p>Password: "******"</p><p>Click <a href=" + appUrl + ">here</a> to login</p><p>Thanks again for signing up!</p>" + "<p>The AR Team</p></body></html>"; bool sendPassword = EmailHelper.SendEmail("Welcome to LivaKart", model.Email, emailbody); if (sendPassword) { response.Message = "Company created successfully. Password has been sent to their email."; } else { logging.Info("Password sending failed to newly created user named " + model.Email); response.Message = "Company created successfully but Password sending failed."; response.Status = ConstantUtil.StatusFail; } } } } catch (Exception ex) { logging.Error(ex.ToString()); } } return(Json(response, JsonRequestBehavior.AllowGet)); }
private string GetUrl(IconInfo iconInfo) { return(UrlUtility.GetAbsoluteUrl(new HttpContextWrapper(Context), iconInfo.Url)); }
/// <summary> /// Gets the permanent URL for the <see cref="WxeFunction"/> of the specified <paramref name="functionType"/> /// and using the <paramref name="urlParameters"/>. /// </summary> /// <include file='..\doc\include\ExecutionEngine\WxeContext.xml' path='WxeContext/GetPermanentUrl/param[@name="httpContext" or @name="functionType" or @name="urlParameters" or @name="fallbackOnCurrentUrl"]' /> protected static string GetPermanentUrl(HttpContextBase httpContext, Type functionType, NameValueCollection urlParameters, bool fallbackOnCurrentUrl) { ArgumentUtility.CheckNotNull("httpContext", httpContext); ArgumentUtility.CheckNotNull("functionType", functionType); if (!typeof(WxeFunction).IsAssignableFrom(functionType)) { throw new ArgumentException(string.Format("The functionType '{0}' must be derived from WxeFunction.", functionType), "functionType"); } ArgumentUtility.CheckNotNull("urlParameters", urlParameters); NameValueCollection internalUrlParameters = NameValueCollectionUtility.Clone(urlParameters); UrlMapping.UrlMappingEntry mappingEntry = UrlMapping.UrlMappingConfiguration.Current.Mappings[functionType]; if (mappingEntry == null) { string functionTypeName = WebTypeUtility.GetQualifiedName(functionType); internalUrlParameters.Set(WxeHandler.Parameters.WxeFunctionType, functionTypeName); } string path; if (mappingEntry == null) { string defaultWxeHandler = Configuration.WebConfiguration.Current.ExecutionEngine.DefaultWxeHandler; if (string.IsNullOrEmpty(defaultWxeHandler)) { if (fallbackOnCurrentUrl) { path = httpContext.Request.Url.AbsolutePath; } else { throw new WxeException( string.Format( "No URL mapping has been defined for WXE Function '{0}', nor has a default WxeHandler URL been specified in the application configuration (web.config).", functionType.FullName)); } } else { path = defaultWxeHandler; } } else { path = mappingEntry.Resource; } string permanentUrl = UrlUtility.GetAbsoluteUrl(httpContext, path) + UrlUtility.FormatQueryString(internalUrlParameters, httpContext.Response.ContentEncoding); int maxLength = Configuration.WebConfiguration.Current.ExecutionEngine.MaximumUrlLength; if (permanentUrl.Length > maxLength) { throw new WxePermanentUrlTooLongException( string.Format( "Error while creating the permanent URL for WXE function '{0}'. " + "The URL exceeds the maximum length of {1} bytes. Generated URL: {2}", functionType.Name, maxLength, permanentUrl)); } return(permanentUrl); }
public ActionResult EditCompany(Company model, string returnUrl) { JsonResponse response = new JsonResponse(); response.Message = ConstantUtil.MessageError; response.Status = ConstantUtil.StatusFail; try { if (!string.IsNullOrEmpty(model.Image) && !System.IO.File.Exists(Server.MapPath(CompanyImagesPath) + model.Image.Split('/').Last()) && System.IO.File.Exists(Server.MapPath(TempPath) + model.Image.Split('/').Last())) { System.IO.File.Copy(Server.MapPath(TempPath) + model.Image.Split('/').Last(), Server.MapPath(CompanyImagesPath) + model.Image.Split('/').Last()); model.Image = UrlUtility.GetAbsoluteUrl(CompanyImagesPath + model.Image.Split('/').Last()); } var companyEntity = _companyService .Query(x => x.CompanyId == model.CompanyId) .Include(x => x.User) .Select().SingleOrDefault(); companyEntity.CompanyId = model.CompanyId; companyEntity.CompanyName = model.CompanyName; companyEntity.ContactPerson = model.ContactPerson; companyEntity.Address1 = model.Address1; companyEntity.Address2 = model.Address2; companyEntity.State = model.State; companyEntity.City = model.City; companyEntity.Zip = model.Zip; companyEntity.CountryID = model.CountryID; companyEntity.Phone = model.Phone; companyEntity.Email = model.Email; companyEntity.UserName = model.UserName; companyEntity.Active = model.Active; companyEntity.ModifiedBy = CurrentUser; companyEntity.ModifiedDate = DateTime.UtcNow; companyEntity.Image = model.Image; companyEntity.UserName = companyEntity.User.UserName; companyEntity.VuforiaServerAccessKey = model.VuforiaServerAccessKey; companyEntity.VuforiaServerSecretKey = model.VuforiaServerSecretKey; companyEntity.VuforiaClientAccessKey = model.VuforiaClientAccessKey; companyEntity.VuforiaClientSecretKey = model.VuforiaClientSecretKey; _companyService.Update(companyEntity); bool success = _unitOfWorkAsync.SaveChanges() > 0; if (success) { //Set the current culture if country changes string countryCode = _companyService.FindCountry(model.CountryID).CountryCode2; countryCode = string.IsNullOrEmpty(countryCode) ? "US" : countryCode; var cultureInfo = CultureInfo.GetCultures(CultureTypes.AllCultures).Where(c => c.Name.EndsWith(countryCode)).FirstOrDefault(); cultureInfo = cultureInfo == null ? new CultureInfo("en-US") : cultureInfo; Thread.CurrentThread.CurrentCulture = cultureInfo; ((User)Session["ActiveUser"]).CultureCode = cultureInfo.CompareInfo.Name; ((User)Session["ActiveUser"]).Image = model.Image; Session["Photo"] = model.Image; logging.Info("Profile updated successfully."); response.Message = "Profile updated successfully."; response.Status = ConstantUtil.StatusOk; response.ReturnUrl = returnUrl; var obj = _companyService.Find(model.CompanyId); Session["CurrentCompany"] = obj; } } catch (Exception ex) { logging.Error(ex.ToString()); } return(Json(response, JsonRequestBehavior.AllowGet)); }