private string ProcessUploadedFile(CreateFreelancerViewModel model) { string uniqueFileName = null; if (model.photo != null) { string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + model.photo.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { model.photo.CopyTo(fileStream); } } return(uniqueFileName); }
public async Task <IActionResult> Register(CreateFreelancerViewModel viewmodel) { if (ModelState.IsValid) { string uniqueFileName = ProcessUploadedFile(viewmodel); Freelancer freelancer = new Freelancer(); freelancer.freelancerId = currentUser; freelancer.englishProficiency = (int)viewmodel.englishProficiency; string userId = User.GetUserId(); freelancer.hourlyRate = Convert.ToDouble(viewmodel.hourlyRate); freelancer.photo = uniqueFileName; freelancer.title = viewmodel.title; freelancer.status = (int)Constants.status.Active; freelancer.phoneNumber = viewmodel.phoneNumber; freelancer.professionalOverview = viewmodel.professionalOverview; Language lang = new Language(); lang.userId = currentUser; lang.language = (int)viewmodel.language; Address address = new Address(); address.region = viewmodel.region; address.city = viewmodel.city; address.woreda = viewmodel.woreda; address.houseNumber = Convert.ToInt32(viewmodel.houseNumber.ToString()); address.pobox = Convert.ToInt32(viewmodel.pobox.ToString()); address.userId = currentUser; Expertise expertise = new Expertise(); expertise.skill = (int)viewmodel.skill; expertise.category = (int)viewmodel.category; expertise.level = viewmodel.expertiseStatus; expertise.status = "not verified"; Experience experience = new Experience(); experience.companyName = viewmodel.companyName; experience.title = viewmodel.expTitle; experience.description = viewmodel.description; experience.freelancerId = currentUser; experience.location = viewmodel.location; experience.startDate = viewmodel.startDate; experience.endDate = viewmodel.endDate; Wallet wall = new Wallet(); wall.userId = RegisterModel.registeredUser; wall.balance = 0; walletRepository.Deposit(wall); _context.Add(freelancer); await _context.SaveChangesAsync(); _context.Add(address); await _context.SaveChangesAsync(); _context.Add(expertise); await _context.SaveChangesAsync(); _context.Add(experience); await _context.SaveChangesAsync(); _context.Add(lang); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Home")); } return(View(viewmodel)); }