public ActionResult UploadFile()
        {
            TblEvents events = new TblEvents();


            try
            {
                var    file        = Request.Form.Files[0];
                string folderName  = "Upload";                              // folderul unde se afla pozele
                string webRootPath = _hostingEnvironment.WebRootPath;       // obtine calea wwwroot
                string newPath     = Path.Combine(webRootPath, folderName); // combina cele doua wwwrooth si upload - wwwroot\\upload
                if (!Directory.Exists(newPath))
                {
                    Directory.CreateDirectory(newPath);
                }
                if (file.Length > 0)
                {
                    string fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); // preia numele pzoei - poza.jpg
                    events.Photo = '/' + folderName + '/' + fileName;
                    string fullPath = Path.Combine(newPath, fileName);                                                 // creeaza calea spre poza wwwroot\\upload\\poza
                    using (var stream = new FileStream(fullPath, FileMode.Create))
                    {
                        file.CopyTo(stream);// copiaza tot nume , lungimea pozei
                    }
                }
                return(Json("Upload Successful."));
            }
            catch (System.Exception ex)
            {
                return(Json("Upload Failed: " + ex.Message));
            }
        }
Beispiel #2
0
 public TblEvents GetEventData(int id)
 {
     try
     {
         TblEvents events = db.TblEvent.Find(id);
         return(events);
     }
     catch
     {
         throw;
     }
 }
Beispiel #3
0
 public int DeleteEvent(int id)
 {
     try
     {
         TblEvents events = db.TblEvent.Find(id);
         db.TblEvent.Remove(events);
         db.SaveChanges();
         return(1);
     }
     catch
     {
         throw;
     }
 }
Beispiel #4
0
        public int UpdateEvent(TblEvents events)
        {
            try
            {
                string cute_String;
                string MyString = events.Photo;
                cute_String            = MyString.Remove(0, 12);
                events.Photo           = cute_String;
                db.Entry(events).State = EntityState.Modified;
                db.SaveChanges();

                return(1);
            }
            catch
            {
                throw;
            }
        }
Beispiel #5
0
        public int AddEvent(TblEvents events)
        {
            try
            {
                string cute_String;
                string MyString = events.Photo;
                cute_String  = MyString.Remove(0, 12);
                events.Photo = cute_String;
                db.TblEvent.Add(events);

                db.SaveChanges();
                return(1);
            }
            catch
            {
                throw;
            }
        }
 public int Edit([FromBody] TblEvents events)
 {
     return(objevent.UpdateEvent(events));
 }
 public int Create([FromBody] TblEvents events)
 {
     return(objevent.AddEvent(events));
 }