public ActionResult CreateProfile(UserProfile user, HttpPostedFileBase file, HttpPostedFileBase file1) { var loggedInUserr = Session["LoggedInUser"] as User; if (loggedInUserr == null) { return(RedirectToAction("Login", "Account")); } // For Profile Picture "~/Images" // string URL = ""; if (file != null && file.ContentLength > 0) { try { if (file != null && file.ContentLength > 0) { string path = Path.Combine(Server.MapPath("~/Images"), Path.GetFileName(file.FileName.Replace(' ', '-'))); if (System.IO.File.Exists(path)) { var newPath = Path.Combine(Server.MapPath("~/Images"), Path.GetFileNameWithoutExtension(file.FileName.Replace(' ', '-')).ToString() + DateTime.Now.ToString("yyyy-MM-dd HHmmtt") + Path.GetExtension(file.FileName)); newPath = newPath.Replace(' ', '-').ToString(); URL = CommonCls.GetURL() + "/Images/" + Path.GetFileNameWithoutExtension(file.FileName.Replace(' ', '-')).ToString() + DateTime.Now.ToString("yyyy-MM-dd HHmmtt") + Path.GetExtension(file.FileName); URL = URL.Replace(' ', '-').ToString(); file.SaveAs(newPath); } else { file.SaveAs(path); URL = CommonCls.GetURL() + "/Images/" + file.FileName.Replace(' ', '-'); } } } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } ////// Company Logo URL1 /////// string URL1 = ""; if (file1 != null && file1.ContentLength > 0) { try { if (file1 != null && file1.ContentLength > 0) { string path = Path.Combine(Server.MapPath("~/Images"), Path.GetFileName(file1.FileName.Replace(' ', '-'))); if (System.IO.File.Exists(path)) { var newPath = Path.Combine(Server.MapPath("~/Images"), Path.GetFileNameWithoutExtension(file1.FileName.Replace(' ', '-')).ToString() + DateTime.Now.ToString("yyyy-MM-dd HHmmtt") + Path.GetExtension(file1.FileName)); newPath = newPath.Replace(' ', '-').ToString(); URL1 = CommonCls.GetURL1() + "/Images/" + Path.GetFileNameWithoutExtension(file1.FileName.Replace(' ', '-')).ToString() + DateTime.Now.ToString("yyyy-MM-dd HHmmtt") + Path.GetExtension(file1.FileName); URL1 = URL1.Replace(' ', '-').ToString(); file1.SaveAs(newPath); } else { file1.SaveAs(path); URL1 = CommonCls.GetURL1() + "/Images/" + file1.FileName.Replace(' ', '-'); } } } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } //Save user Userinfo usr = new Userinfo(); usr.UserId = loggedInUserr.Id; usr.Name = user.Name; usr.Middlename = user.Middlename; usr.Lastname = user.Lastname; usr.City = user.City; usr.Email = user.Email; usr.Zipcode = user.Zipcode; usr.Designation = user.Designation; usr.CellNo = user.CellNo; usr.Brokerage = user.Brokerage; usr.OfficeNo = user.OfficeNo; usr.Website = user.Website; usr.PhotoPath = URL; usr.CompanyLogo = URL1; usr.OfficeAddress = user.OfficeAddress; dba.Userinfos.InsertOnSubmit(usr); dba.SubmitChanges(); return(RedirectToAction("Index", "Dashboard")); }
public ActionResult Edit(int Userinfoid, UserProfile Model, HttpPostedFileBase file, HttpPostedFileBase file1) { var loggedInUserr = Session["LoggedInUser"] as User; if (loggedInUserr == null) { return(RedirectToAction("Login", "Account")); } using (var dba = new DataClasses1DataContext()) { Userinfo usr = dba.Userinfos.Where(val => val.Userinfoid == Model.Userinfoid).Single <Userinfo>(); // var custTemp = new Customer_temp(); string URL = usr.PhotoPath; if (file != null && file.ContentLength > 0) { try { if (usr.PhotoPath != "") { // DeleteImage(Customer.PhotoPath); } string path = Path.Combine(Server.MapPath("~/Images"), Path.GetFileName(file.FileName.Replace(' ', '-'))); if (System.IO.File.Exists(path)) { var newPath = Path.Combine(Server.MapPath("~/Images"), Path.GetFileNameWithoutExtension(file.FileName.Replace(' ', '-')).ToString() + DateTime.Now.ToString("yyyy-MM-dd HHmmtt") + Path.GetExtension(file.FileName)); newPath = newPath.Replace(' ', '-').ToString(); URL = CommonCls.GetURL() + "/Images/" + Path.GetFileNameWithoutExtension(file.FileName.Replace(' ', '-')).ToString() + DateTime.Now.ToString("yyyy-MM-dd HHmmtt") + Path.GetExtension(file.FileName); URL = URL.Replace(' ', '-').ToString(); file.SaveAs(newPath); } else { file.SaveAs(path); URL = CommonCls.GetURL() + "/Images/" + file.FileName.Replace(' ', '-'); } // custTemp.PhotoPath = URL; usr.PhotoPath = URL; } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } // Company Logo // string URL1 = usr.CompanyLogo; if (file1 != null && file1.ContentLength > 0) { try { if (usr.CompanyLogo != "") { // DeleteImage(Customer.CompanyLogo); } string path = Path.Combine(Server.MapPath("~/Images"), Path.GetFileName(file1.FileName.Replace(' ', '-'))); if (System.IO.File.Exists(path)) { var newPath = Path.Combine(Server.MapPath("~/Images"), Path.GetFileNameWithoutExtension(file1.FileName.Replace(' ', '-')).ToString() + DateTime.Now.ToString("yyyy-MM-dd HHmmtt") + Path.GetExtension(file1.FileName)); newPath = newPath.Replace(' ', '-').ToString(); URL1 = CommonCls.GetURL1() + "/Images/" + Path.GetFileNameWithoutExtension(file1.FileName.Replace(' ', '-')).ToString() + DateTime.Now.ToString("yyyy-MM-dd HHmmtt") + Path.GetExtension(file1.FileName); URL1 = URL1.Replace(' ', '-').ToString(); file1.SaveAs(newPath); } else { file1.SaveAs(path); URL1 = CommonCls.GetURL1() + "/Images/" + file1.FileName.Replace(' ', '-'); } // custTemp.CompanyLogo = URL1; usr.CompanyLogo = URL1; } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } usr.Userinfoid = Model.Userinfoid; usr.Name = Model.Name; usr.Middlename = Model.Middlename; usr.Lastname = Model.Lastname; usr.City = Model.City; usr.Email = Model.Email; usr.Zipcode = Model.Zipcode; usr.Designation = Model.Designation; usr.CellNo = Model.CellNo; usr.Brokerage = Model.Brokerage; usr.OfficeNo = Model.OfficeNo; usr.Website = Model.Website; //usr.PhotoPath = URL; usr.OfficeAddress = Model.OfficeAddress; //usr.CompanyLogo = URL1; dba.SubmitChanges(); return(RedirectToAction("Index", "Dashboard")); } }