public async Task <IActionResult> Add(IndexPromoterViewModel model) { if (!this.ModelState.IsValid) { model.ProjectsItems = this.projectService.GetAllAsKeyValuePair(); model.GroupsItems = this.groupService.GetAllAsKeyValuePair(); return(this.View(model)); } if (model.ImagePhoto != null) { string folder = "Promoters/images/"; model.Gallery = new List <GalleryPromoterViewModel>(); model.ImageUrl = await this.UploadImage(folder, model.ImagePhoto); } if (model.GalleryFiles != null) { string folder = "Promoters/gallery/"; foreach (var file in model.GalleryFiles) { var gallery = new GalleryPromoterViewModel() { Name = file.FileName, Url = await this.UploadImage(folder, file), }; model.Gallery.Add(gallery); } } await this.promotersService.CreateAsync(model); return(this.Redirect("/Promoters/All")); }
public async Task CreateAsync(IndexPromoterViewModel model) { var promoter = new Promoter { GroupId = model.GroupId, ProjectId = model.ProjectId, FirstName = model.FirstName, LastName = model.LastName, Description = model.Description, Email = model.Email, Gender = model.Gender, Skills = model.Skills, Mobile = model.Mobile, Age = model.Age, Language = model.Language, ImageUrl = model.ImageUrl, City = model.City, District = model.District, }; foreach (var file in model.Gallery) { promoter.PromoterGalleries.Add(new PromoterGallery { Name = file.Name, Url = file.Url, }); } await this.promoteRepository.AddAsync(promoter); await this.promoteRepository.SaveChangesAsync(); }
public IActionResult Add() { var viewModel = new IndexPromoterViewModel { ProjectsItems = this.projectService.GetAllAsKeyValuePair(), GroupsItems = this.groupService.GetAllAsKeyValuePair(), }; return(this.View(viewModel)); }
public async Task CreateAsyncEdit(IndexPromoterViewModel model) { var promoter = new Promoter { GroupId = model.GroupId, ProjectId = model.ProjectId, FirstName = model.FirstName, LastName = model.LastName, Description = model.Description, Email = model.Email, Gender = model.Gender, Skills = model.Skills, Mobile = model.Mobile, Age = model.Age, Language = model.Language, ImageUrl = model.ImageUrl, City = model.City, District = model.District, }; await this.promoteRepository.AddAsync(promoter); await this.promoteRepository.SaveChangesAsync(); }