public async Task <IActionResult> ExperienceCreate(ExperienceCreateUpdateModel model, int[] selectedCategoryIds, IFormFile file) { if (ModelState.IsValid) { var user = await _UserManager.FindByNameAsync(User.Identity.Name); var entity = new Experience() { Name = model.Name, Title = model.Title, Author = model.Author, Body = model.Body, LocationId = model.LocationOfExperience.LocationId, BeenThereUserId = user.Id, ImageUrl = "defaultExperiencePic.jpg" }; var locationOfExperience = _LocationService.GetById(model.LocationOfExperience.LocationId); await UpdateCountryCodeList(user.Id.ToString(), locationOfExperience.CountryCode, null); if (file != null) { var extention = Path.GetExtension(file.FileName); var randomName = string.Format($"{Guid.NewGuid()}{extention}"); entity.ImageUrl = randomName; var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot//img", randomName); using (var stream = new FileStream(path, FileMode.Create)) { await file.CopyToAsync(stream); } } _ExperienceService.Create(entity); _ExperienceService.AddCategoriesToExperience(entity, selectedCategoryIds); if (model.LocationOfExperience.LocationId > 0) { var locationToBeEdited = _LocationService.GetById(model.LocationOfExperience.LocationId); _LocationService.AttachCategoriesToLocation(locationToBeEdited, selectedCategoryIds); } return(Redirect("/social/experiencedetails/" + entity.ExperienceId)); } return(View(model)); }
public IActionResult AddExperience(Experience entity) { ViewBag.resumepages = new SelectList(_resumepageService.GetAll(), "ResumepageId", "ResumepageTitle"); if (ModelState.IsValid) { _experienceService.Create(entity); TempData.Put("message", new ResultMessage() { Title = "Bildirim", Message = "Tecrübe Bilgisi başarılı bir şekilde oluşturuldu.", Css = "success" }); return(RedirectToAction("Experiences")); } return(View(entity)); }
public ActionResult Create([FromRoute] int systemUserId, [FromBody] NewExperienceViewModel model) { var experience = new UserExperienceModel { CompanyName = model.CompanyName, EndMonth = model.EndMonth, EndYear = model.EndYear, StartMonth = model.StartMonth, StartYear = model.StartYear, Title = model.Title, SystemUserId = systemUserId, IsCurrentlyWorkHere = model.IsCurrentlyWorkHere, Resume = model.Resume }; _experienceService.Create(experience); return(Ok(MessageHelper.Success("The experience have been created."))); }