public IHttpActionResult PutAbout(AboutViewModel model) { using (var context = new MyPortfolioEntities()) { var data = context.abouts .Where(x => x.id_about == model.id_about) .FirstOrDefault <about>(); if (data != null) { data.id_about = model.id_about; data.current_position = model.current_position; data.birthday = model.birthday; data.city = model.city; data.country = model.country; data.age = model.age; data.degree = model.degree; context.SaveChanges(); } else { return(NotFound()); } } return(Ok()); }
public IHttpActionResult PutSocial(ContactViewModel model) { using (var db = new MyPortfolioEntities()) { var data = db.contacts .Where(x => x.id_contact == model.id_contact) .FirstOrDefault <contact>(); if (data != null) { data.instagram = model.instagram; data.twitter = model.twitter; data.facebook = model.facebook; data.linkedin = model.linkedin; data.github = model.github; db.SaveChanges(); } else { return(NotFound()); } } return(Ok()); }
public IHttpActionResult Put(PorfolioViewModel model) { if (!ModelState.IsValid) { return(BadRequest("Invalid Update Portofolio")); } using (db) { var data = db.portfolios.Where(x => x.id_portfolio == model.id_portfolio).FirstOrDefault <portfolio>(); if (data != null) { data.id_portfolio = model.id_portfolio; data.id_category = model.id_category; data.portfo_name = model.portfo_name; db.SaveChanges(); } else { return(NotFound()); } } return(Ok()); }
public IHttpActionResult Post(PorfolioViewModel model) { if (!ModelState.IsValid) { return(BadRequest("Not data entry")); } using (db) { db.categorys.Add(new category() { category_name = model.category_name, }); db.SaveChanges(); } return(Ok()); }
public IHttpActionResult PutImage() { //Check if Request contains File. if (HttpContext.Current.Request.Files.Count == 0) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } //Read the File data from Request.Form collection. HttpPostedFile postedFile = HttpContext.Current.Request.Files["image_upload"]; var id = HttpContext.Current.Request["id"]; var iid = Convert.ToInt32(id); if (!ModelState.IsValid) { return(BadRequest("Invalid Update Image Profile")); } using (var db = new MyPortfolioEntities()) { var data = db.users.Where(x => x.id_user == iid).FirstOrDefault <user>(); var oldImage = HttpContext.Current.Request.MapPath(data.image_path); if (data != null) { var file = Path.GetFileNameWithoutExtension(postedFile.FileName); var extension = Path.GetExtension(postedFile.FileName); var fileName = file + DateTime.Now.ToString("yymmssff") + extension; postedFile.SaveAs(HttpContext.Current.Server.MapPath("/Assets/Profile/") + fileName); byte[] bytes; using (BinaryReader br = new BinaryReader(postedFile.InputStream)) { bytes = br.ReadBytes(postedFile.ContentLength); } data.image_byte = bytes; data.image_title = fileName; data.image_path = "/Assets/Profile/" + fileName; if (db.SaveChanges() > 0) { if (System.IO.File.Exists(oldImage)) { System.IO.File.Delete(oldImage); } return(Ok()); } } } return(Ok()); }
public IHttpActionResult Post(SkillViewModel model) { using (var data = new MyPortfolioEntities()) { data.skills.Add(new skill() { id_skill = model.id_skill, skill_name = model.skill_name, skill_value = model.skill_value }); data.SaveChanges(); } return(Ok()); }
public IHttpActionResult Delete(int id) { if (id <= 0) { return(BadRequest("Id Not found")); } using (var db = new MyPortfolioEntities()) { var data = db.skills.Where(x => x.id_skill == id).FirstOrDefault(); db.Entry(data).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); } return(Ok()); }
public IHttpActionResult Post() { //Create HTTP Response. HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK); //Check if Request contains File. //Read the File data from Request.Form collection. HttpPostedFile postedFile = HttpContext.Current.Request.Files["image_upload"]; var category = HttpContext.Current.Request["id_category"]; var title = HttpContext.Current.Request["portfo_name"]; var file = Path.GetFileNameWithoutExtension(postedFile.FileName); var extension = Path.GetExtension(postedFile.FileName); var filename = file + DateTime.Now.ToString("yymmssff") + extension; postedFile.SaveAs(HttpContext.Current.Server.MapPath("/Assets/Images/") + filename); //Convert the File data to Byte Array. byte[] bytes; using (BinaryReader br = new BinaryReader(postedFile.InputStream)) { bytes = br.ReadBytes(postedFile.ContentLength); } //Insert the File to Database Table. MyPortfolioEntities db = new MyPortfolioEntities(); portfolio porfo = new portfolio { portfo_name = title, id_category = Convert.ToInt32(category), image_title = filename, image_path = "/Assets/Images/" + filename, image_byte = bytes }; db.portfolios.Add(porfo); db.SaveChanges(); return(Ok()); }
public IHttpActionResult Post(ServiceViewModel model) { if (!ModelState.IsValid) { return(BadRequest("Data Not Valid")); } using (var db = new MyPortfolioEntities()) { db.services.Add(new service() { id_service = model.id_service, service_name = model.service_name, service_content = model.service_content, }); db.SaveChanges(); } return(Ok()); }
public IHttpActionResult Delete(int Id) { MyPortfolioEntities db = new MyPortfolioEntities(); var porto = db.portfolios.Find(Id); string image = HttpContext.Current.Request.MapPath(porto.image_path); db.Entry(porto).State = System.Data.Entity.EntityState.Deleted; if (db.SaveChanges() > 0) { if (System.IO.File.Exists(image)) { System.IO.File.Delete(image); } return(Ok()); } return(Ok()); }
public IHttpActionResult Put(SkillViewModel model) { using (var db = new MyPortfolioEntities()) { var data = db.skills.Where(x => x.id_skill == model.id_skill).FirstOrDefault <skill>(); if (data != null) { data.skill_name = model.skill_name; data.skill_value = model.skill_value; db.SaveChanges(); } else { return(NotFound()); } } return(Ok()); }
public IHttpActionResult PutResume(AboutViewModel model) { using (var context = new MyPortfolioEntities()) { var data = context.abouts .Where(x => x.id_about == model.id_about) .FirstOrDefault <about>(); if (data != null) { data.id_about = model.id_about; data.about_me = model.about_me; context.SaveChanges(); } else { return(NotFound()); } } return(Ok()); }
public IHttpActionResult Put(ServiceViewModel model) { if (!ModelState.IsValid) { return(BadRequest("Invalid Data Put")); } using (var db = new MyPortfolioEntities()) { var data = db.services.Where(x => x.id_service == model.id_service).FirstOrDefault <service>(); if (data != null) { data.service_name = model.service_name; data.service_content = model.service_content; db.SaveChanges(); } else { return(NotFound()); } } return(Ok()); }
public IHttpActionResult PutContact(ContactViewModel model) { using (var db = new MyPortfolioEntities()) { var data = db.contacts .Where(x => x.id_contact == model.id_contact) .FirstOrDefault <contact>(); if (data != null) { data.id_contact = model.id_contact; data.address = model.address; data.phone = model.phone; data.email = model.email; db.SaveChanges(); } else { return(NotFound()); } } return(Ok()); }
public IHttpActionResult Put(ProfileViewModel model) { var db = new MyPortfolioEntities(); UserResponse resp = new UserResponse(); using (db) { var data = db.users.Where(x => x.id_user == model.id_user).FirstOrDefault <user>(); if (data != null) { data.email = model.email; data.name = model.name; data.password = model.password; db.SaveChanges(); } else { return(BadRequest("Update Filed")); } } return(Ok()); }