Exemplo n.º 1
0
 public static ImagesModel GetById(int id)
 {
     var context = new Ecommerce.DbEntity.ecommerceEntities();
     var col = context.images.Where(m => m.id == id).FirstOrDefault();
     var Image = new ImagesModel();
     Image.id = col.id;
     Image.image = col.image1;
     Image.Type = col.imageType;
     return Image;
 }
Exemplo n.º 2
0
 public static bool Update(ImagesModel obj)
 {
     bool check = true;
     try
     {
         var context = new Ecommerce.DbEntity.ecommerceEntities();
         var image = context.images.Where(m => m.id == obj.id).FirstOrDefault();
         image.image1 = obj.image;
         context.SaveChanges();
     }
     catch (Exception ex)
     {
         check = false;
     }
     return check;
 }
Exemplo n.º 3
0
        public ActionResult Save(ImagesModel obj)
        {
            bool check = true;
              if (Request.IsAuthenticated)
              {
              string path = "";
              if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
              {

                  path = Path.Combine(Server.MapPath("~/img/"), obj.image);
                  try
                  {
                      System.IO.File.Delete(path);
                  }
                  catch
                  {
                      // if there is exception in deleting the file
                  }
                  var file = Request.Files[0];
                  var _guid = Guid.NewGuid();
                  var _fileName = "";
                  var extention = Path.GetExtension(file.FileName);

                  _fileName = obj.Type  + extention;
                  if (file != null && file.ContentLength > 0)
                  {
                      path = Path.Combine(Server.MapPath("~/img/"), _fileName);
                      file.SaveAs(path);
                      obj.image = _fileName;
                  }
              }
              check = ImageDal.Update(obj);
              if (check)
              {
                  TempData["message"] = "Saved successfully";
              }
              else
              {
                  TempData["message"] = "Error while saving data";
              }
              return RedirectToAction("index", "image");
              }
              else
              {
              return RedirectToAction("index", "home");
              }
        }