protected override void Seed(DefaultDbContext ctx) { ImageToByteConverter converter = new ImageToByteConverter(); ctx.People.AddRange(new Person[] { new Person { FirstName = "First name 1", LastName = "Last name 1", MiddleName = "Middle name 1", Image = converter.Convert(Image.FromFile("person.png")) } }); ctx.SaveChanges(); }
public async Task <IActionResult> Register(InputRegisterModel model, string userImage) { if (ModelState.IsValid) { byte[] image = ImageToByteConverter.Convert(userImage); ActionMessage response = await userService.CreateAccount(model, image); if (User.Identity.IsAuthenticated) { return(RedirectToAction("ActionMessage", "Dashboard", response)); } else { return(RedirectToAction("Login", "Auth")); } } return(View(model)); }
public Wall GetWall(long walId) { try { string query = @"SELECT walId, walName, walDescription, walImage FROM Wall WHERE walId = @walId"; using (SqlConnection conn = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand(query, conn); cmd.Parameters.AddWithValue("@walId", walId); conn.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { if (dr.Read()) { var image = ImageToByteConverter.ConvertToByteArray(new Bitmap(Rage.Addservice.Persistence.Properties.Resources.default_wall_image)); return(new Wall() { Id = (dr[0] == null || dr[0] == DBNull.Value) ? (long?)null : Convert.ToInt64(dr[0]), Name = (dr[1] == null || dr[1] == DBNull.Value) ? null : Convert.ToString(dr[1]), Description = (dr[2] == null || dr[2] == DBNull.Value) ? null : Convert.ToString(dr[2]), Image = (dr[3] == null || dr[3] == DBNull.Value) ? image : (Byte[])dr[3] }); } else { return(null); } } } } catch (Exception ex) { throw new Exception("Error GetWall: " + ex.Message); } }
public void AddProduct(NewProductWM webModel) { #region AddProductValidations List <AddProductValidationBase> validationList = new List <AddProductValidationBase>(); validationList.Add(new CheckProductImagePath()); validationList.Add(new CheckProductCategory()); validationList.Add(new CheckProductName()); validationList.Add(new CheckProductUnitPrice()); validationList[0].SetNextValidation(validationList[1]); validationList[1].SetNextValidation(validationList[2]); validationList[2].SetNextValidation(validationList[3]); validationList[0].Execute(webModel); bool webModelValid = validationList[validationList.Count - 1].IsValid; #endregion if (webModelValid) { try { Bitmap image = new Bitmap(webModel.ImagePath); ProductImages productImage = new ProductImages { ProductPicture = ImageToByteConverter.ConvertImagePath(image) }; _productImagesOperations.AddProductImage(productImage); _productsOperations.AddProduct(ProductsMapping.MapToEntity(webModel.Product)); } catch (Exception ex) { throw new Exception(ex.ToString()); } } }
public List <Wall> GetWalls() { try { string query = @"SELECT walId, walName, walDescription, walImage FROM Wall"; using (SqlConnection conn = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand(query, conn); conn.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { List <Wall> walls = new List <Wall>(); var image = ImageToByteConverter.ConvertToByteArray(new Bitmap(Rage.Addservice.Persistence.Properties.Resources.default_wall_image)); while (dr.Read()) { walls.Add(new Wall() { Id = (dr[0] == null || dr[0] == DBNull.Value) ? (long?)null : Convert.ToInt64(dr[0]), Name = (dr[1] == null || dr[1] == DBNull.Value) ? null : Convert.ToString(dr[1]), Description = (dr[2] == null || dr[2] == DBNull.Value) ? null : Convert.ToString(dr[2]), Image = (dr[3] == null || dr[3] == DBNull.Value) ? image : (Byte[])dr[3] }); } return(walls.Count > 0 ? walls : null); } } } catch (Exception ex) { throw new Exception("Error GetWalls: " + ex.Message); } }