public async Task <bool> CreateInspiratorAsync(InspiratorCreateEditServiceModel model) { if (model.Name == null || model.BirthDate < new DateTime(1900, 1, 1) || model.BirthDate > new DateTime(2017, 1, 1)) { return(false); } var inspirator = new Inspirator(); inspirator.Name = model.Name; inspirator.Posts = new List <Post>(); inspirator.BirthDate = model.BirthDate; if (model.Image != null) { using (var memoryStream = new MemoryStream()) { await model.Image.CopyToAsync(memoryStream); inspirator.Image = memoryStream.ToArray(); } } await this.context.Inspirators.AddAsync(inspirator); await this.context.SaveChangesAsync(); return(true); }
public async Task <bool> EditPostAsync(Category category, Inspirator inspirator, string quote, string postId, User author) { var post = await this.context.Posts.FirstOrDefaultAsync(p => p.Id == postId); if (post == null || category == null || inspirator == null || quote.Length > 600 || author == null) { return(false); } post.Author = author; post.Category = category; post.Quote = quote; post.Inspirator = inspirator; await context.SaveChangesAsync(); return(true); }
public async Task <bool> CreatePostAsync(User author, Category category, Inspirator inspirator, string quote) { if (author == null || category == null || inspirator == null) { return(false); } Post post = new Post(); post.Author = author; post.Category = category; post.Inspirator = inspirator; post.Quote = quote; post.Likes = new List <Like>(); post.Created = DateTime.UtcNow; await this.context.Posts.AddAsync(post); await this.context.SaveChangesAsync(); return(true); }
public static PlayerUnit create_punit(int ID, int owner_ID) { PlayerUnit pu = null; if (ID == WARRIOR) { pu = new Warrior(); } else if (ID == SPEARMAN) { pu = new Spearman(); } else if (ID == ARCHER) { pu = new Archer(); } else if (ID == MINER) { pu = new Miner(); } else if (ID == INSPIRATOR) { pu = new Inspirator(); } else if (ID == SEEKER) { pu = new Seeker(); } else if (ID == GUARDIAN) { pu = new Guardian(); } else if (ID == ARBALEST) { pu = new Arbalest(); } else if (ID == SKIRMISHER) { pu = new Skirmisher(); } else if (ID == PALADIN) { pu = new Paladin(); } else if (ID == MENDER) { pu = new Mender(); } else if (ID == DRUMMER) { pu = new Drummer(); } else if (ID == PIKEMAN) { pu = new Pikeman(); } else if (ID == CARTER) { pu = new Carter(); } else if (ID == DRAGOON) { pu = new Dragoon(); } else if (ID == SCOUT) { pu = new Scout(); } else if (ID == SHIELD_MAIDEN) { pu = new ShieldMaiden(); } pu.owner_ID = owner_ID; return(pu); }