public ActionResult Edit(PortfolioBindingModel model, HttpPostedFileBase image) { try { if (image != null) { FileInfo file = new FileInfo(image.FileName); var getEmailName = User.Identity.Name.Split('@')[0]; var fileName = Path.GetFileName(getEmailName + file.Extension); var location = Path.Combine( Server.MapPath("~/App_Data/ProfilePics"), fileName); if (System.IO.File.Exists(location)) { System.IO.File.Delete(location); } image.SaveAs(location); } service.UpdatePortfolio(model, User.Identity.Name, ""); return(RedirectToAction("MyPortfolio", "Portfolio")); } catch { return(View()); } }
public PortfolioBindingModel GetPortfolioBindingModel(int?id) { if (id > -1) { using (var context = new PortfolioDatabase()) { var result = context.Portfolio_table .FirstOrDefault(p => p.Id == id); if (result != null) { var bindingModel = new PortfolioBindingModel() { FirstName = result.FirstName, LastName = result.LastName, PhoneNumber = result.PhoneNumber, Age = result.Age, EducationHighSchool = result.EducationHighSchool, EducationCollege = result.EducationCollege, Experience = result.Experience, ExperienceYears = result.ExperienceYears, AboutMe = result.AboutMe, Services = result.Services, FacebookAccount = result.Facebook, TwitterAccount = result.Twitter }; return(bindingModel); } } } return(null); }
//public public void UploadPortfolio(PortfolioBindingModel model, string Creator, string imageLocation) { try { PortfolioDataModel dataModel = new PortfolioDataModel { ImageLocation = imageLocation, FirstName = model.FirstName, LastName = model.LastName, PhoneNumber = model.PhoneNumber, Email = Creator, Age = model.Age, EducationHighSchool = model.EducationHighSchool, EducationCollege = model.EducationCollege, Experience = model.Experience, ExperienceYears = model.ExperienceYears, AboutMe = model.AboutMe, Services = model.Services, Facebook = model.FacebookAccount, Twitter = model.TwitterAccount, CVLocation = "" }; using (var context = new PortfolioDatabase()) { if (context.Portfolio_table != null) { if (context.Portfolio_table .FirstOrDefault(u => u.Email == Creator) == null) { context.Portfolio_table.Add(dataModel); context.SaveChanges(); } } else { context.Portfolio_table.Add(dataModel); context.SaveChanges(); } } } catch (Exception ex) { throw ex; } }
public void UpdatePortfolio(PortfolioBindingModel model, string Creator, string ImageLocation) { try { PortfolioDataModel dataModel = new PortfolioDataModel { ImageLocation = ImageLocation, FirstName = model.FirstName, LastName = model.LastName, PhoneNumber = model.PhoneNumber, Email = Creator, Age = model.Age, EducationHighSchool = model.EducationHighSchool, EducationCollege = model.EducationCollege, Experience = model.Experience, ExperienceYears = model.ExperienceYears, AboutMe = model.AboutMe, Services = model.Services, Facebook = model.FacebookAccount, Twitter = model.TwitterAccount, CVLocation = "" }; using (var context = new PortfolioDatabase()) { var result = context.Portfolio_table.FirstOrDefault(p => p.Email == Creator); if (ImageLocation == "") { dataModel.ImageLocation = result.ImageLocation; } context.Portfolio_table.Remove(result); context.Portfolio_table.Add(dataModel); context.SaveChanges(); } } catch (Exception ex) { throw ex; } }
public ActionResult Create(PortfolioBindingModel model, HttpPostedFileBase image) { try { if (image != null) { FileInfo file = new FileInfo(image.FileName); var getEmailName = User.Identity.Name.Split('@')[0]; var fileName = Path.GetFileName(getEmailName + file.Extension); var location = Path.Combine( Server.MapPath("~/App_Data/ProfilePics"), fileName); image.SaveAs(location); service.UploadPortfolio(model, User.Identity.Name, location); return(RedirectToAction("Index", "Home")); } return(View()); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); return(View()); } }