public IHttpActionResult SendMessage(ContactUs _contactinfo) { try { string result = String.Empty; string body = PortalUtility.GetEmailTemplate("ContactUs.txt"); body = body.Replace("#NAME#", _contactinfo.FullName); body = body.Replace("#EMAIL#", _contactinfo.EmailAddress); body = body.Replace("#SUBJECT#", _contactinfo.Subject); body = body.Replace("#MESSAGE#", _contactinfo.Message); result = PortalUtility.SendEmail(_contactinfo.Subject, body); if (String.IsNullOrEmpty(result)) { result = "Message Sent"; } return(Ok(result)); } catch (Exception ex) { PortalUtility.SendErrorEmail(ex); return(new PortalUtility.PlainTextResult(ex.Message, HttpStatusCode.InternalServerError)); } }
public IHttpActionResult Login(Login login) { //try { PortalUtility.ValidateAntiForgeryToken(); } //catch { return new PortalUtility.PlainTextResult("Invalid Request Token", HttpStatusCode.BadRequest); } try { bool isvalidlogin = Models.Login.ValidateLogin(login.UserName, login.Password); if (isvalidlogin) { FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, login.UserName, DateTime.Now, DateTime.Now.AddMinutes(30), true, ""); String cookiecontents = FormsAuthentication.Encrypt(authTicket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, cookiecontents) { Expires = authTicket.Expiration, Path = FormsAuthentication.FormsCookiePath }; HttpContext.Current.Response.Cookies.Add(cookie); return(Ok()); } else { LogoutTasks(); return(new PortalUtility.PlainTextResult("Authentication Exception", HttpStatusCode.NotFound)); } } catch (Exception ex) { PortalUtility.SendErrorEmail(ex); return(new PortalUtility.PlainTextResult(ex.Message, HttpStatusCode.InternalServerError)); } }
public IHttpActionResult DeleteTempImage(string imagename) { try { if (User.IsInRole("ADMIN")) { PortalUtility.CleanupTempFiles(); string path_thumb = Path.Combine(HttpContext.Current.Server.MapPath(Models.RecipeImage.Path_TempThumbnail), imagename); string path_full = Path.Combine(HttpContext.Current.Server.MapPath(Models.RecipeImage.Path_TempStandard), imagename); if (File.Exists(path_thumb)) { File.Delete(path_thumb); } if (File.Exists(path_full)) { File.Delete(path_full); } } return(Ok()); } catch (Exception ex) { PortalUtility.SendErrorEmail(ex); return(new PortalUtility.PlainTextResult("Upload failed: " + ex.Message, HttpStatusCode.InternalServerError)); } }
public IHttpActionResult Search(Models.RecipeSearch searchdata) { try { string[] categories = (from itm in searchdata.SearchCategoryList where itm.IsSelected select itm.CategoryCode).ToArray(); List <Models.Recipe> allresults = Models.Recipe.SearchRecipes(searchdata.SearchText, new string[] { }, categories); searchdata.SearchResultText = allresults.Count.ToString() + " Recipies Found"; searchdata.PageSize = 10; searchdata.PageCount = PortalUtility.PagerHelper.GetPageCount(searchdata.PageSize, allresults.Count); searchdata.PageNumber = PortalUtility.PagerHelper.CheckPageValid(searchdata.PageNumber, searchdata.PageCount); if (searchdata.PageNumber < 1) { searchdata.PageNumber = 1; } searchdata.SearchResults = new List <Models.Recipe>(); if (allresults.Count > 0) { int startindex = ((searchdata.PageNumber - 1) * searchdata.PageSize); int range = searchdata.PageSize; if (startindex + range > allresults.Count) { range = allresults.Count - startindex; } searchdata.SearchResults = allresults.GetRange(startindex, range); } return(Ok(searchdata)); } catch (Exception ex) { PortalUtility.SendErrorEmail(ex); return(new PortalUtility.PlainTextResult(ex.Message, HttpStatusCode.InternalServerError)); } }
public IHttpActionResult SaveRecipe(Models.Recipe rcp) { try { if (User.IsInRole("ADMIN")) { int index = 0; foreach (Models.RecipeIngredient ing in rcp.IngredientList) { ing.SortOrder = index++; } index = 0; foreach (Models.RecipeDirection dir in rcp.DirectionList) { dir.SortOrder = index++; } index = 0; foreach (Models.RecipeImage img in rcp.ImageList) { img.SortOrder = index++; } rcp.SaveRecipe(); } return(Ok(rcp.RecipeID)); } catch (Exception ex) { PortalUtility.SendErrorEmail(ex); return(new PortalUtility.PlainTextResult(ex.Message, HttpStatusCode.InternalServerError)); } }
public IHttpActionResult GetTopNavigation() { try { return(Ok(Models.NavItem.GetTopNavigation())); } catch (Exception ex) { PortalUtility.SendErrorEmail(ex); return(new PortalUtility.PlainTextResult(ex.Message, HttpStatusCode.InternalServerError)); } }
public IHttpActionResult GetRecipe(string recipeId, int quantity = 1) { try { return(Ok(new Recipe(recipeId, quantity))); } catch (Exception ex) { PortalUtility.SendErrorEmail(ex); return(new PortalUtility.PlainTextResult(ex.Message, HttpStatusCode.InternalServerError)); } }
public IHttpActionResult CanUserEditRecipes() { try { return(Ok(User.IsInRole("FULLACCESS"))); } catch (Exception ex) { PortalUtility.SendErrorEmail(ex); return(new PortalUtility.PlainTextResult(ex.Message, HttpStatusCode.InternalServerError)); } }
public IHttpActionResult GetAllCategories() { try { List <Models.Recipe.Category> categories = Models.Recipe.Category.GetAllCategories(); return(Ok(categories)); } catch (Exception ex) { PortalUtility.SendErrorEmail(ex); return(new PortalUtility.PlainTextResult(ex.Message, HttpStatusCode.InternalServerError)); } }
public IHttpActionResult DeleteRecipe(string recipeId) { try { if (User.IsInRole("ADMIN")) { Models.Recipe.DeleteRecipe(recipeId); } return(Ok()); } catch (Exception ex) { PortalUtility.SendErrorEmail(ex); return(new PortalUtility.PlainTextResult(ex.Message, HttpStatusCode.InternalServerError)); } }
public IHttpActionResult UploadImage() { if (User.IsInRole("ADMIN")) { try { PortalUtility.CleanupTempFiles(); string imagelist = String.Empty; foreach (string file in HttpContext.Current.Request.Files) { HttpPostedFile fileContent = HttpContext.Current.Request.Files[file]; if (fileContent != null && fileContent.ContentLength > 0) { // get a stream string imagename = GetImageName(); string path_thumb = Path.Combine(HttpContext.Current.Server.MapPath(Models.RecipeImage.Path_TempThumbnail), imagename); string path_full = Path.Combine(HttpContext.Current.Server.MapPath(Models.RecipeImage.Path_TempStandard), imagename); Stream stream = fileContent.InputStream; Image img = Image.FromStream(stream); Image thumbimg = PortalUtility.ScaleImage(img, 100, 100); thumbimg.Save(path_thumb, System.Drawing.Imaging.ImageFormat.Png); Image regimg = PortalUtility.ScaleImage(img, 800, 600); regimg.Save(path_full, System.Drawing.Imaging.ImageFormat.Png); imagelist += imagename + ","; } } imagelist = imagelist.Trim(','); string[] returnval = imagelist.Split(','); return(Ok(returnval)); } catch (Exception ex) { PortalUtility.SendErrorEmail(ex); return(new PortalUtility.PlainTextResult("Upload failed: " + ex.Message, HttpStatusCode.InternalServerError)); } } else { return(new PortalUtility.PlainTextResult("Demo login does not allow image uploads.", HttpStatusCode.Unauthorized)); } }
public IHttpActionResult AddNewUser(Login login) { try { string resultmsg = string.Empty; if (User.IsInRole("ADMIN")) { resultmsg = login.AddNewUser(); } else { resultmsg = "Success"; } return(Ok(resultmsg)); } catch (Exception ex) { PortalUtility.SendErrorEmail(ex); return(new PortalUtility.PlainTextResult(ex.Message, HttpStatusCode.InternalServerError)); } }
public IHttpActionResult CreateDataBackupScripts() { try { string recipesaveproc = "call Recipe_SaveRecipe('{0}','{1}',0,pRecipeID);"; string ingredientsaveproc = "call Recipe_SaveIngredient(0,pRecipeID,'{0}',{1},'{2}','{3}','{4}',{5},pIngredientID);"; string directionsaveproc = "call Recipe_SaveDirections(0,pRecipeID,{0},'{1}','{2}',pDirectionID);"; string categorysaveproc = "call Recipe_SaveRecipeCategory(pRecipeID,'{0}');"; string imagesaveproc = "call Recipe_SaveImage(pRecipeID,'{0}','{1}','{2}');"; StringBuilder backupscript = new StringBuilder(); backupscript.AppendLine("declare pRecipeID varchar(36);"); backupscript.AppendLine("declare pIngredientID int;"); backupscript.AppendLine("declare pDirectionID int;"); backupscript.AppendLine(); backupscript.AppendLine("TRUNCATE TABLE Recipe_Recipes;"); backupscript.AppendLine("TRUNCATE TABLE Recipe_Ingredients;"); backupscript.AppendLine("TRUNCATE TABLE Recipe_Directions;"); backupscript.AppendLine("TRUNCATE TABLE Recipe_Categories;"); backupscript.AppendLine("TRUNCATE TABLE Recipe_Images;"); backupscript.AppendLine(); List <Models.Recipe> recipes = Models.Recipe.SearchRecipes(String.Empty, new string[] { }, new string[] { }); foreach (Models.Recipe item in recipes) { Models.Recipe rcp = new Models.Recipe(item.RecipeID); backupscript.AppendLine(String.Format(recipesaveproc, rcp.Title.Replace("'", "''"), rcp.Description.Replace("'", "''"))); foreach (Models.RecipeIngredient ing in rcp.IngredientList) { backupscript.AppendLine(String.Format(ingredientsaveproc, ing.IngredientName.Trim().Replace("'", "''"), ing.Quantity, ing.UnitOfMeasure.Replace("'", "''"), ing.Notes.Trim().Replace("'", "''"), ing.DisplayType, ing.SortOrder)); } foreach (Models.RecipeDirection dir in rcp.DirectionList) { backupscript.AppendLine(String.Format(directionsaveproc, dir.SortOrder, dir.DirectionText.Trim().Replace("'", "''"), dir.DisplayType)); } foreach (Models.Recipe.Category ctg in rcp.CategoryList) { backupscript.AppendLine(String.Format(categorysaveproc, ctg.CategoryCode)); } foreach (Models.RecipeImage img in rcp.ImageList) { backupscript.AppendLine(String.Format(imagesaveproc, img.ImageName, img.IsPrimary, img.SortOrder)); } backupscript.AppendLine(); backupscript.AppendLine(); } System.IO.File.WriteAllText(System.Web.Hosting.HostingEnvironment.MapPath("~/DownloadFiles/DataRestoreScript.txt"), backupscript.ToString()); return(Ok("Success")); } catch (Exception ex) { PortalUtility.SendErrorEmail(ex); return(new PortalUtility.PlainTextResult(ex.Message, HttpStatusCode.InternalServerError)); } }