public Task <int> CreateDeveloper(IDeveloper developer)
        {
            var developerModel = _mapper.Map <IDeveloper, Developer>(developer);

            _uow.AddAsync(_mapper.Map <Developer, DeveloperEntity>(developerModel));
            return(_uow.CommitAsync());
        }
        public async Task <int> CreateGenreAsync(IGameGenre genre)
        {
            var model  = _mapper.Map <IGameGenre, GameGenre>(genre);
            var entity = _mapper.Map <GameGenre, GameGenreEntity>(model);
            await _uow.AddAsync(entity);

            return(await _uow.CommitAsync());
        }
        public static async Task CreateChatMessages(this IUnitOfWork unitOfWork, string stock, string owner, string message, int count, DateTime sentTime)
        {
            for (int i = 1; i <= count; i++)
            {
                await unitOfWork.AddAsync(EntityFactory.GetChatMessage(stock, owner, $"{message} {i}", sentTime.AddDays(i)));
            }

            await unitOfWork.SaveChangesAsync();
        }
Beispiel #4
0
 /// <summary>
 /// Asynchronously insert a new T to database.
 /// </summary>
 /// <param name="entity"></param>
 /// <returns>Number of created entities.</returns>
 public async Task <int> AddAsync(IEnumerable <T> entities)
 {
     foreach (var entity in entities)
     {
         var tentity = _automapper.Map <TEntity>(entity);
         await _uow.AddAsync(tentity);
     }
     return(await _uow.CommitAsync());
 }
Beispiel #5
0
        public Task <int> CreateCart(ICart cart)
        {
            #region UOW
            var cartmodel = _mapper.Map <ICart, Cart>(cart);
            _uow.AddAsync(_mapper.Map <Cart, CartEntity>(cartmodel));
            _uow.CommitAsync();
            return(Task.FromResult(1));

            #endregion
        }
        /// <summary>
        /// Create Vehicle and save to database.
        /// </summary>
        /// <returns>Vehicle</returns>
        async Task <Vehicle> IVehicleRepository.CreateVehicle(SaveVehicleResource vehicleResource)
        {
            var vehicle = Vmapper.Map <SaveVehicleResource, Vehicle>(vehicleResource);

            await UnitOfWork.AddAsync(vehicle);

            await UnitOfWork.CommitAsync();

            return(vehicle);
        }
 public virtual Task<int> AddAsync(IUnitOfWork unitOfWork, IUser entity)
 {
     try
     {
         return unitOfWork.AddAsync<User>(
             Mapper.Map<User>(entity));
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Beispiel #8
0
        /// <summary>
        /// Adds comments and updates recipe with raiting
        /// </summary>
        /// <param name="review">Comment</param>
        /// <returns>Comment</returns>
        public async Task <IComment> InsertICommentAsync(IComment entity)
        {
            try
            {
                IUnitOfWork uow = Repository.CreateUnitOfWork();

                Comment result = await uow.AddAsync <Comment>(Mapper.Map <Comment>(entity));

                await uow.CommitAsync();

                return(Mapper.Map <IComment>(result));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #9
0
        public async Task <int> AddAsync(IVehicleMake entity)
        {
            if (entity is VehicleMake)
            {
                try
                {
                    await _unitOfWork.AddAsync <VehicleMake>(entity as VehicleMake);

                    return(await _unitOfWork.SaveChangesAsync());
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            else
            {
                throw new ArgumentException();
            }
        }
Beispiel #10
0
 public async Task AddAsync(AccountCardDetails cardDetails, CancellationToken ct = default(CancellationToken))
 {
     await _unitOfWork.AddAsync(cardDetails, ct);
 }
        public virtual async Task<int> AddAsync(IUnitOfWork unitOfWork, List<IUser> entities,
            List<IUserRole> roles = null)
        {
            try
            {
                var result = 0;

                foreach (var entity in entities)
                {
                    result += await this.AddAsync(unitOfWork, entity);
                }

                if (roles != null)
                {
                    foreach (var role in roles)
                    {
                        result += await unitOfWork.AddAsync<UserRole>(
                            Mapper.Map<UserRole>(role));
                    }
                }
                return result;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #12
0
 /// <summary>
 /// Adds a new current record to the database and a version 1 record
 /// </summary>
 /// <param name="account">The account to add</param>
 /// <param name="ct">Operation cancellation</param>
 public async Task AddAsync(Account account, CancellationToken ct = default(CancellationToken))
 {
     await _unitOfWork.AddAsync(account, ct);
 }
 public virtual Task<int> AddAsync(IUnitOfWork unitOfWork, IUserRole entity)
 {
     var userRole = Mapper.Map<SchedulerModel.UserRolePOCO>(entity);
     var dalUserRole = Mapper.Map<SchedulerModel.UserRolePOCO, DALModel.UserRole>(userRole);
     return unitOfWork.AddAsync<DALModel.UserRole>(dalUserRole);
 }
Beispiel #14
0
 /// <summary>
 /// Adds a new current record to the database and a version 1 record
 /// </summary>
 /// <param name="roomBooking">The roomBooking to add</param>
 /// <param name="ct">Operation cancellation</param>
 public async Task AddAsync(RoomBooking booking, CancellationToken ct = default(CancellationToken))
 {
     await _unitOfWork.AddAsync(booking, ct);
 }