public IHttpActionResult GetUserById(int id) { ProfileViewModel model = null; //BaseResponse baseResponse = new BaseResponse(); UserResponse res = new UserResponse(); using (var db = new MyPortfolioEntities()) { model = db.users.Where(x => x.id_user == id).Select(x => new ProfileViewModel() { id_user = x.id_user, name = x.name, image_path = x.image_path, email = x.email, password = x.password, username = x.username, id_role = x.role.id_role, role_name = x.role.role_name }).FirstOrDefault <ProfileViewModel>(); } if (model == null) { return(NotFound()); } return(Ok(model)); }
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 Get() { ContactViewModel model = new ContactViewModel(); using (var db = new MyPortfolioEntities()) { model = db.contacts.Select(x => new ContactViewModel() { id_contact = x.id_contact, address = x.address, phone = x.phone, email = x.email, instagram = x.instagram, twitter = x.twitter, facebook = x.facebook, linkedin = x.linkedin, github = x.github }).FirstOrDefault <ContactViewModel>(); } if (model == null) { return(NotFound()); } return(Ok(model)); }
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 Get() { AboutViewModel model = new AboutViewModel(); using (var data = new MyPortfolioEntities()) { model = data.abouts.Select(x => new AboutViewModel() { id_about = x.id_about, about_me = x.about_me, current_position = x.current_position, birthday = x.birthday, city = x.city, country = x.country, age = x.age, degree = x.degree }).FirstOrDefault <AboutViewModel>(); } if (model == null) { return(NotFound()); } return(Ok(model)); }
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 Get() { IList <SkillViewModel> model = null; using (var db = new MyPortfolioEntities()) model = db.skills.Select(x => new SkillViewModel() { id_skill = x.id_skill, skill_name = x.skill_name, skill_value = x.skill_value }).ToList(); if (model.Count == 0) { return(NotFound()); } return(Ok(model)); }
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 Get() { IList <ServiceViewModel> model = null; using (var db = new MyPortfolioEntities()) { model = db.services.Select(x => new ServiceViewModel() { id_service = x.id_service, service_name = x.service_name, service_content = x.service_content }).ToList <ServiceViewModel>(); } if (model.Count == 0) { return(NotFound()); } return(Ok(model)); }
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 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 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()); }