public HttpResponseMessage UploadImage() { string imageName = null; var httpRequest = System.Web.HttpContext.Current.Request; //Upload image var postedFile = httpRequest.Files["Image"]; //Createcustom filename imageName = new String(Path.GetFileNameWithoutExtension(postedFile.FileName).Take(10).ToArray()).Replace(" ", "-"); imageName = imageName + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postedFile.FileName); string p = new string(HttpContext.Current.Server.MapPath("").Take(75).ToArray()); int a = HttpContext.Current.Server.MapPath("").Length; var filiPathNew = p + "\\Images\\" + imageName; var filePath = HttpContext.Current.Server.MapPath("~/Images/" + imageName); postedFile.SaveAs(filePath); using (Models.DbModel db = new Models.DbModel()) { Image image = new Image() { ImageCaption = httpRequest["ImageCaption"], ImageName = imageName }; db.Image.Add(image); db.SaveChanges(); } return(Request.CreateResponse(HttpStatusCode.Created)); }
public IHttpActionResult GetCustName(string searcher) { Models.DbModel db = new Models.DbModel(); var result = db.Items.Where(x => x.Name.StartsWith(searcher) || searcher == null).ToList(); return(Ok(result)); }
public IHttpActionResult Put(Guid id, SaaS__Abonnement em) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } using (var ctx = new Models.DbModel()) { var existingAbo = ctx.SaaS__Abonnement.Where(e => e.ID_ == id) .FirstOrDefault <SaaS__Abonnement>(); if (existingAbo != null) { existingAbo.Title = em.Title; existingAbo.Description = em.Description; ctx.SaveChanges(); } else { return(NotFound()); } } return(Ok()); }
public IHttpActionResult PostSaaS__Abonnement(SaaS__Abonnement saaS__Abonnement) { //if (!ModelState.IsValid) //{ // return BadRequest(ModelState); //} using (var db = new Models.DbModel()) { saaS__Abonnement = new SaaS__Abonnement() { ID_ = Guid.NewGuid(), Title = saaS__Abonnement.Title, Description = saaS__Abonnement.Description }; db.SaaS__Abonnement.Add(saaS__Abonnement); db.SaveChanges(); } return(CreatedAtRoute("DefaultApi", new { id = saaS__Abonnement.ID_ }, saaS__Abonnement)); // return Ok(); //try //{ // db.SaveChanges(); //} //catch (DbUpdateException) //{ // if (SaaS__AbonnementExists(saaS__Abonnement.ID_)) // { // return Conflict(); // } // else // { // throw; // } //} //return CreatedAtRoute("DefaultApi", new { id = saaS__Abonnement.ID_ }, saaS__Abonnement); }
public static string GetToken() { Models.DbModel db = new Models.DbModel(); string token; bool duplicate = true; do { Guid g = Guid.NewGuid(); token = Convert.ToBase64String(g.ToByteArray()); token = token.Replace("=", ""); token = token.Replace("+", ""); token = token.Replace("/", ""); //check if newly created token is unique if (!db.JDE_Tenants.Where(x => x.TenantToken == token).Any()) { if (!db.JDE_Places.Where(x => x.PlaceToken == token).Any()) { if (!db.JDE_Parts.Where(x => x.Token == token).Any()) { if (!db.JDE_Files.Where(x => x.Token == token).Any()) { if (!db.JDE_StorageBins.Where(x => x.Token == token).Any()) { duplicate = false; } } } } } } while (duplicate); return(token); }
public TreeService(Zadanie_Testowe.Models.DbModel zadanieTestoweEntities) { Db = zadanieTestoweEntities; }