public IActionResult CompanyDetails(EmployerCompanyModel FromData) { // Display User name on the right-top corner - shows user is logedIN ViewData["LoggeduserName"] = new List <string>() { _user.UserFirstName + ' ' + _user.UserLastName, _user.UserImage }; // Geting Dashboard Menu from project/data/DashboardMenuOption.json into ViewData string path = _env.ContentRootPath + @"\Data\DashboardMenuOptions.json"; ViewData["menuItems"] = HelpersFunctions.GetMenuOptionsForUser(_user.UserId, path); using (GlobalDBContext _context = new GlobalDBContext()) { if (FromData.CompanyLogo != null && FromData.CompanyLogo.Length > 0) { string uploadFolder = _env.WebRootPath + @"\uploads\CompanyLogos\"; // File of code need to be Tested //string file_Path = HelpersFunctions.StoreFile(uploadFolder, generalProfile.UserImage); string uniqueFileName = Guid.NewGuid().ToString() + "_" + FromData.CompanyLogo.FileName; string filePath = uploadFolder + uniqueFileName; FileStream stream = new FileStream(filePath, FileMode.Create); FromData.CompanyLogo.CopyTo(stream); stream.Dispose(); // Delete previous uploaded Image if (!String.IsNullOrEmpty(_company.UserCompanyLogo)) { string imagePath = uploadFolder + _company.UserCompanyLogo; if (System.IO.File.Exists(imagePath)) { // If file found, delete it System.IO.File.Delete(imagePath); Console.WriteLine("File deleted."); } } // if new image is uploaded with other user info _company.AddFromEmployerCompanyModel(FromData, uniqueFileName); } else { // Adding generalProfile attr to user without image _company.AddFromEmployerCompanyModel(FromData); } _context.UserCompany.Update(_company); _context.SaveChanges(); FromData.CompanyLogoName = _company.UserCompanyLogo; return(View(FromData)); } }
public void AddFromEmployerCompanyModel(EmployerCompanyModel form, string fileName = null) { UserCompanyName = form.CompanyName; if (fileName != null) { UserCompanyLogo = fileName; } UserCompanyType = form.CompanyType; UserCompanyInfo = form.CompanyInfo; UserCompanyAddress = form.CompanyLocation; UserCompanyState = form.CompanyState; UserCompanyCountry = form.CompanyCountry; }
public UserCompany(EmployerCompanyModel form, User _user, string fileName = null) { UserCompanyName = form.CompanyName; if (fileName != null) { UserCompanyLogo = fileName; } UserCompanyType = form.CompanyType; UserCompanyInfo = form.CompanyInfo; UserCompanyAddress = form.CompanyLocation; UserCompanyState = form.CompanyState; UserCompanyCountry = form.CompanyCountry; User = _user; }