示例#1
0
        public IHttpActionResult UploadRecording([FromBody] Sampling Sampling, HttpPostedFileBase file)
        {
            string Message  = "";
            string fileName = "";

            // string extension = Path.GetExtension(file.FileName);

            try
            {
                if (ModelState.IsValid)
                {
                    Sampling.AudioFileName = file.FileName;
                    _context.Samplings.Add(Sampling);
                    _context.SaveChanges();
                    Message = "1";
                    return(Ok(Message));
                }



                if (file != null && file.ContentLength > 0)
                {
                    fileName = Path.GetFileName(file.FileName);
                    var path = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~/Uploads/Audio"), fileName);
                    file.SaveAs(path);
                }
                Message = "1";
                return(Ok(Message));
            }
            catch (Exception ex)
            {
                Message = "0";
                return(Ok(ex.Message));
            }
        }
示例#2
0
 public Boolean EditBird(Bird bird)
 {
     try
     {
         _birdContext.Entry(bird).State = EntityState.Modified;
         _birdContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public ActionResult Create(Species collection)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _context.Species.Add(collection);
             _context.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(collection));
     }
     catch
     {
         return(View());
     }
 }
示例#4
0
 public ActionResult Create(Taxonomy taxonomy)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _context.Taxonomies.Add(taxonomy);
             _context.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(taxonomy));
     }
     catch
     {
         return(View());
     }
 }
示例#5
0
 public Boolean BirdCountAdded(User_has_birds newBird)
 {
     try
     {
         _birdContext.User_has_birds.Add(newBird);
         _birdContext.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public ActionResult Create(Taxonomy model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //create path to store in database
                    string filename = model.Imagepath.FileName.ToString();
                    model.ImageURL = filename;
                    model.Imagepath.SaveAs(Server.MapPath("~/Uploads") + "/" + model.Imagepath.FileName);

                    //model.Imagepath = fileName;
                    _context.Taxonomies.Add(model);
                    _context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                return(View(model));
            }
            catch
            {
                return(View());
            }
        }