public virtual IViewModel <T, long> Add(BaseInputModel <T, long> input) { Auth.AuthorizeAdd(); Logger.Information($"Add {typeof(T).FullName}"); Validator.Validate(input); var newObj = Mapper.Map <T>(input); Repo.AddEntity(newObj); Repo.Save(); Logger.Information($"Added {typeof(T).FullName} Id:{newObj?.Id}"); return(Mapper.Map <IViewModel <T> >(newObj)); }
/// <summary> /// Intended mainly for many-to-many join endpoints, this method /// allows you to submit many entities at once. /// </summary> /// <param name="inputs">New entities to create.</param> /// <returns>The saved entities (including their database ids).</returns> public virtual IViewModel <T, long>[] AddMany(BaseInputModel <T, long>[] inputs) { Auth.AuthorizeAdd(); Logger.Information($"Add {typeof(T).FullName}"); foreach (var input in inputs) { Validator.Validate(input); } var newObjs = Mapper.Map <T[]>(inputs); foreach (var obj in newObjs) { Repo.AddEntity(obj); } Repo.Save(); Logger.Information($"Added {typeof(T).FullName} Ids:{newObjs.Select(n => n.Id).ToArray()}"); return(Mapper.Map <IViewModel <T>[]>(newObjs)); }