Ejemplo n.º 1
0
 public void InsertImageInfo(Image_info imageInfo)
 {
     int id = Convert.ToInt32(context.Database.SqlQuery<int>("GetImageInfoMaxID").FirstOrDefault()) + 1;
     context.Image_info.Add(imageInfo);
 }
Ejemplo n.º 2
0
 public void UpdateImageInfo(Image_info imageInfo)
 {
     context.Entry(imageInfo).State = EntityState.Modified;
 }
Ejemplo n.º 3
0
        public ActionResult Edit(Menu menu, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {

                try
                {
                    Image_info bigImage = new Image_info();
                    Image_info smallImage = new Image_info();
                    Menu oldMenu = (Menu)Session["menu"];
                    menu.Create_date = oldMenu.Create_date;
                    menu.Modified_date = System.DateTime.Now;
                    menu.Big_Image_id = oldMenu.Big_Image_id;
                    menu.Menu_id = oldMenu.Menu_id;
                    menu.Small_Image_id = oldMenu.Small_Image_id;
                    menu.menu_type_id = oldMenu.menu_type_id;
                    oldMenu.Image_info.Description = menu.Image_info.Description;
                    oldMenu.Image_info1.Description = menu.Image_info1.Description;
                    oldMenu.Menu_type.type_name = menu.Menu_type.type_name;

                    menu.Image_info = oldMenu.Image_info;
                    menu.Image_info1 = oldMenu.Image_info1;
                    menu.Menu_type = oldMenu.Menu_type;
                    file = Request.Files[0];
                    if (file != null && file.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(file.FileName);
                        //smallPicture.Name = fileName;
                        if (fileName == null)
                        {
                            //menu.Image_info.Image_id
                        }

                        string target = @"~/Images/profile/" + menu.Menu_name + GetHashCode().ToString();

                        if (!Directory.Exists(Server.MapPath(target)))
                        {
                            Directory.CreateDirectory(Server.MapPath(target));
                        }
                        var newPath = Path.Combine(Server.MapPath(target), fileName);
                        file.SaveAs(newPath);

                        //smallPicture.Path = newPath;
                        //smallPicture.Description = menu.Image_info1.Description;

                        //repo.InsertImageInfo(smallPicture);
                        //repo.Save();

                        menu.Image_info1.Name = fileName;
                        menu.Image_info1.Path = target;

                        //menu.Small_Image_id = repo.GetImageIDByName(smallPicture.Name);
                    }

                    file = Request.Files[1];

                    if (file != null && file.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(file.FileName);
                        //bigPicture.Name = fileName;

                        string target = @"~/Images/profile/" + menu.Menu_name + GetHashCode().ToString();

                        if (!Directory.Exists(Server.MapPath(target)))
                        {
                            Directory.CreateDirectory(Server.MapPath(target));
                        }
                        var newPath = Path.Combine(Server.MapPath(target), fileName);
                        file.SaveAs(newPath);

                        //bigPicture.Path = newPath;
                        //bigPicture.Description = menu.Image_info.Description;

                        //repo.InsertImageInfo(bigPicture);
                        //repo.Save();
                        menu.Image_info.Name = fileName;
                        menu.Image_info.Path = target;
                        //menu.Big_Image_id = repo.GetImageIDByName(bigPicture.Name);
                    }

                    repo.UpdateMenu(menu);
                    //repo.InsertMenu(menu);
                    repo.Save();
                    return RedirectToAction("MenuIndex");
                }
                catch (Exception ex)
                {
                    //get the innermost exception
                    while (ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                    }
                    ModelState.AddModelError("", "error on create: " + ex.GetBaseException().Message);
                }
            }
            //ViewBag.Big_Image_id = new SelectList(db.Image_info, "Image_id", "Path", menu.Big_Image_id);
            //ViewBag.Small_Image_id = new SelectList(db.Image_info, "Image_id", "Path", menu.Small_Image_id);
            return View(menu);
        }