public async Task <int> CreateAsync(ActivityRequestModel model) { var activity = new Data.Models.Activity { Description = model.Description, Name = model.Name }; await _dbContext.AddAsync(activity); await _dbContext.SaveChangesAsync(); return(activity.Id); }
public async Task <int> CreateAsync(AboutRequestModel model) { var about = new Data.Models.About { Description = model.Description, Headline = model.Headline, Links = model.Links.Select(l => new Link { Description = l.Description, Position = l.Position, Url = l.Url, ViewName = l.ViewName }).ToList() }; await _dbContext.AddAsync(about); await _dbContext.SaveChangesAsync(); return(about.Id); }
public async Task <int> CreateAsync(EmployeeRequestModel model) { var vCard = new VCard() { FirstName = model.FirstName, LastName = model.LastName, JobTitle = model.JobTitle, Organization = model.VCard.Organization, Phone = model.VCard.Phone, Street = model.VCard.Street, PostalCode = model.VCard.PostalCode, City = model.VCard.City, Country = model.VCard.Country, Email = model.VCard.Email, HomePage = model.VCard.HomePage, Mobile = model.VCard.Mobile }; var employee = new Data.Models.Employee { Description = model.Description, FirstName = model.FirstName, LastName = model.LastName, ImageUrl = model.ImageUrl, JobTitle = model.JobTitle, VCard = vCard }; await _dbContext.AddAsync(employee); await _dbContext.SaveChangesAsync(); foreach (var activity in model.Activities) { var act = await _dbContext .Activities .FirstOrDefaultAsync(a => a.Id == activity.Id); var emp = await _dbContext .Employees .FirstOrDefaultAsync(e => e.Id == employee.Id); if (act == null || emp == null) { continue; } var empAct = new EmployeeActivity { Activity = act, ActivityId = act.Id, Employee = emp, EmployeeId = emp.Id }; await _dbContext.AddAsync(empAct); } await _dbContext.SaveChangesAsync(); return(employee.Id); }