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 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 static void DeleteRecipe(string _recipeid) { using (MySqlConnection conn = new MySqlConnection(PortalUtility.GetConnectionString("default"))) { conn.Open(); //Have to get all current images so we can delete the image files MySqlCommand imgcmd = new MySqlCommand("Recipe_Select_RecipeImages", conn); imgcmd.CommandType = CommandType.StoredProcedure; imgcmd.Parameters.AddWithValue("@pRecipeID", _recipeid); MySqlDataAdapter da = new MySqlDataAdapter(imgcmd); DataSet ds = new DataSet(); da.Fill(ds, "Images"); foreach (DataRow dr in ds.Tables["Images"].Rows) { (new RecipeImage(dr)).DeleteImage(conn); } MySqlCommand cmd = new MySqlCommand("Recipe_DeleteRecipe", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@pRecipeID", _recipeid); cmd.ExecuteNonQuery(); conn.Close(); } }
public string AddNewUser() { string resultmsg = string.Empty; if (!string.IsNullOrEmpty(this.UserName) && !string.IsNullOrEmpty(this.Password)) { this.EncryptionSeed = Guid.NewGuid().ToString(); this.Password = PortalUtility.HashString(this.EncryptionSeed, this.Password); try { using (MySqlConnection conn = new MySqlConnection(PortalUtility.GetConnectionString("default"))) { conn.Open(); MySqlCommand cmd = new MySqlCommand("Security_Insert_User", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@pUsername", this.UserName); cmd.Parameters.AddWithValue("@pPassword", this.Password); cmd.Parameters.AddWithValue("@pEncryptionSeed", this.EncryptionSeed); cmd.ExecuteNonQuery(); conn.Close(); resultmsg = "Success"; } } catch (Exception ex) { resultmsg = ex.Message; } } return(resultmsg); }
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)); } }
protected T ParseFormData <T>() { NameValueCollection form = HttpContext.Current.Request.Params; string[] keys = form.AllKeys; PropertyInfo[] properties = typeof(T).GetProperties(); T model = PortalUtility.ConstructEmpty <T>(); foreach (string key in keys) { PropertyInfo property = properties.Where(p => p.Name == key).SingleOrDefault(); if (property != null) { if (property.PropertyType.Equals(typeof(int))) { property.SetValue(model, int.Parse(form[key])); } if (property.PropertyType.Equals(typeof(string))) { property.SetValue(model, form[key]); } if (property.PropertyType.Equals(typeof(bool))) { property.SetValue(model, bool.Parse(form[key])); } if (property.PropertyType.Equals(typeof(DateTime))) { property.SetValue(model, DateTime.Parse(form[key])); } } } return(model); }
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 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 void SaveDirection() { using (MySqlConnection conn = new MySqlConnection(PortalUtility.GetConnectionString("default"))) { conn.Open(); SaveDirection(conn); conn.Close(); } }
public void DeleteImage() { using (MySqlConnection conn = new MySqlConnection(PortalUtility.GetConnectionString("default"))) { conn.Open(); DeleteImage(conn); conn.Close(); } }
public void SaveCategory(string _recipeid) { using (MySqlConnection conn = new MySqlConnection(PortalUtility.GetConnectionString("default"))) { conn.Open(); SaveCategory(_recipeid, conn); conn.Close(); } }
public IHttpActionResult GetTopNavigation() { try { return(Ok(Models.NavItem.GetTopNavigation())); } catch (Exception ex) { PortalUtility.SendErrorEmail(ex); return(new PortalUtility.PlainTextResult(ex.Message, HttpStatusCode.InternalServerError)); } }
private void LoadDataRow(DataRow dr) { this.IngredientID = Convert.ToInt32(dr["IngredientID"]); this.RecipeID = dr["RecipeID"].ToString(); this.IngredientName = dr["IngredientName"].ToString().Trim(); this.Quantity = Convert.ToDecimal(PortalUtility.CheckDbNull(dr["Quantity"])); this.UnitOfMeasure = dr["UnitOfMeasure"].ToString().Trim(); this.Notes = dr["Notes"].ToString().Trim(); this.SortOrder = Convert.ToInt32(dr["SortOrder"]); this.DisplayType = dr["DisplayType"].ToString(); }
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 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 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 Icon Process(string model) { this.NeedNotNull(model, "icon name"); string name = PortalUtility.UnUrlFormat(model); Icon icon; using (IConnection connection = ConnectionFactory.Create()) { icon = connection.IconByName(name); } if (icon == null) { throw new PortalException(string.Format("Icon '{0}' not found", name)); } return(icon); }
public bool ValidateLogin(string password) { bool isvalid = false; if (!string.IsNullOrEmpty(this.UserName)) { string encryptedpass = PortalUtility.HashString(this.EncryptionSeed, password); if (this.Password == encryptedpass) { isvalid = true; } } return(isvalid); }
public static bool ValidateLogin(string username, string password) { bool isvalid = false; Login userlookup = new Login(username); if (!string.IsNullOrEmpty(userlookup.UserName)) { string encryptedpass = PortalUtility.HashString(userlookup.EncryptionSeed, password); if (userlookup.UserName.ToLower() == username.ToLower() && userlookup.Password == encryptedpass) { isvalid = true; } } return(isvalid); }
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)); } }
private Icon BuildIconFromMessage(IconPost iconPost, IPostedFile file) { Icon icon = new Icon() { Id = iconPost.Id, Name = iconPost.Name, Link = iconPost.Link }; // Force DB name to be correctly formatted icon.Name = PortalUtility.UnUrlFormat(PortalUtility.UrlFormat(icon.Name)); if (file != null) { icon.Image = PortalUtility.GetImageExtension(file.ContentType); } return(icon); }
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 void SaveRecipe() { using (MySqlConnection conn = new MySqlConnection(PortalUtility.GetConnectionString("default"))) { conn.Open(); //Save base recipe information MySqlCommand cmd = new MySqlCommand("Recipe_SaveRecipe", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@pTitle", this.Title); cmd.Parameters.AddWithValue("@pDescription", this.Description); cmd.Parameters.AddWithValue("@pRecipeID", this.RecipeID); cmd.Parameters["@pRecipeID"].Direction = ParameterDirection.Input; cmd.Parameters.Add("@pRecipeIDOut", MySqlDbType.VarString); cmd.Parameters["@pRecipeIDOut"].Direction = ParameterDirection.Output; cmd.ExecuteNonQuery(); //Make sure we have the recipe id if it's a new recipe this.RecipeID = cmd.Parameters["@pRecipeIDOut"].Value.ToString(); //Clear out any existing directions, ingredients, and categories. //This is just easier/lazier than trying to only delete what has been removed cmd = new MySqlCommand("Recipe_ClearData", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@pRecipeID", this.RecipeID); cmd.ExecuteNonQuery(); //Save ingredients foreach (RecipeIngredient ing in this.IngredientList) { ing.RecipeID = this.RecipeID; ing.SaveIngredient(conn); } //Save directions foreach (RecipeDirection dir in this.DirectionList) { dir.RecipeID = this.RecipeID; dir.SaveDirection(conn); } //Save categories foreach (Recipe.Category cat in this.CategoryList) { //only save selected categories if (cat.IsSelected) { cat.SaveCategory(this.RecipeID, conn); } } //Save images foreach (RecipeImage img in this.ImageList) { img.RecipeID = this.RecipeID; img.SaveImage(conn); } //Delete any images that have been removed //Have to do this manually because we need to delete the physical image files cmd = new MySqlCommand("Recipe_Select_RecipeImages", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@pRecipeID", this.RecipeID); MySqlDataAdapter da = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds, "Images"); List <RecipeImage> currentimgs = new List <RecipeImage>(); foreach (DataRow dr in ds.Tables["Images"].Rows) { currentimgs.Add(new RecipeImage(dr)); } foreach (RecipeImage img in currentimgs) { if (!(this.ImageList.Exists(x => x.ImageName == img.ImageName))) { img.DeleteImage(conn); } } conn.Close(); } }
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)); } }