public void AddWallItem(string userId, WallItem wallItem, IEnumerable<string> songsId, string picturePath) { using (var db = new ApplicationDbContext()) { var user = db.Users.FirstOrDefault(m => m.Id == userId); wallItem.AddDate = DateTime.Now; if (user != null) { user.WallItems.Add(wallItem); db.WallItems.Add(wallItem); db.SaveChanges(); if (songsId != null) { foreach (var song in songsId) { db.WallItemsSongs.Add(new WallItemsSongs { SongId = song, WallItemId = wallItem.WallItemId }); } } if (string.IsNullOrEmpty(picturePath) == false) { db.WallItemImages.Add(new WallItemImages { ImagePath = picturePath, WallItemId = wallItem.WallItemId }); } db.SaveChanges(); } } }
public static WallItemViewModel ToWallItemViewModel(WallItem wallItem) { Mapper.CreateMap<WallItem, WallItemViewModel>(); return Mapper.Map<WallItem, WallItemViewModel>(wallItem); }