// GET: api/Routes
 public IEnumerable <RouteDTO> GetRoutes()
 {
     using (var dbcontext = unitOfWorkFactory.CreateUnitOfWork())
     {
         return(Mapper.Map <IEnumerable <Route>, IEnumerable <RouteDTO> >(dbcontext.Routes));
     }
 }
예제 #2
0
 public async Task <List <MonsterType> > GetMonsterTypesWithCategoriesAsync()
 {
     using (var uow = _unitOfWorkFactory.CreateUnitOfWork())
     {
         return(await uow.MonsterTypes.GetAllWithCategoriesAsync());
     }
 }
예제 #3
0
 // GET: api/Discounts
 public IEnumerable <DiscountDTO> GetDiscounts()
 {
     using (var dbcontext = unitOfWorkFactory.CreateUnitOfWork())
     {
         return(Mapper.Map <IEnumerable <Discount>, IEnumerable <DiscountDTO> >(dbcontext.Discounts));
     }
 }
예제 #4
0
        public async Task <IHttpActionResult> PutUser(ChangePasswordDTO changePasswordDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (var dbcontext = unitOfWorkFactory.CreateUnitOfWork())
            {
                try
                {
                    UserDTO userDTO = await Task.Run(() => userModel.ChangePassword(changePasswordDTO, dbcontext));

                    if (userDTO == null)
                    {
                        return(NotFound());
                    }
                    await dbcontext.SaveChangesAsync();

                    return(Ok(userDTO));
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(Conflict());
                }
            }
        }
 // GET: api/Connections
 public IEnumerable <ConnectionDTO> GetConnections()
 {
     using (var dbcontext = unitOfWorkFactory.CreateUnitOfWork())
     {
         return(AutoMapper.Mapper.Map <IEnumerable <Connection>, IEnumerable <ConnectionDTO> >(dbcontext.Connections));
     }
 }
예제 #6
0
        public async Task <IEnumerable <EventLimitedModel> > GetEventsForWorkspace(long workspaceId)
        {
            var unitOfWork = _unitOfWorkFactory.CreateUnitOfWork();
            var results    = await _eventsDAL.GetEventsForWorkspace(unitOfWork, workspaceId);

            return(results);
        }
예제 #7
0
        protected override void OnBackroundExecution()
        {
            int currentServerId = serverId;

            using (IUnitOfWork unitOfWork = unitOfWorkFactory.CreateUnitOfWork(contextSettings))
            {
                if (serverId == 0)
                {
                    InsertNewServer(unitOfWork);
                }
                else
                {
                    UpdateServer(unitOfWork);
                }

                DeleteExpiredServers(unitOfWork);
                unitOfWork.Commit();
            }

            if (currentServerId != serverId)
            {
                ServerDetails             serverDetails = new ServerDetails(serverId, queues);
                ServerRegistrationMessage message       = new ServerRegistrationMessage(serverDetails, this);
                serviceMessageProcessor.SendMessage(message);
            }
        }
예제 #8
0
        public async Task <MonsterTemplate> CreateMonsterTemplateAsync(NaheulbookExecutionContext executionContext, MonsterTemplateRequest request)
        {
            await _authorizationUtil.EnsureAdminAccessAsync(executionContext);

            using (var uow = _unitOfWorkFactory.CreateUnitOfWork())
            {
                var subCategory = await uow.MonsterSubCategories.GetAsync(request.SubCategoryId);

                if (subCategory == null)
                {
                    throw new MonsterSubCategoryNotFoundException(request.SubCategoryId);
                }
                var itemTemplates = await uow.ItemTemplates.GetByIdsAsync(request.Inventory.Select(x => x.ItemTemplateId));

                var monsterTemplate = new MonsterTemplate
                {
                    Data        = JsonConvert.SerializeObject(request.Data),
                    Name        = request.Name,
                    SubCategory = subCategory,
                    Items       = request.Inventory.Where(i => !i.Id.HasValue || i.Id == 0).Select(i => new MonsterTemplateInventoryElement
                    {
                        Chance       = i.Chance,
                        ItemTemplate = itemTemplates.First(x => x.Id == i.ItemTemplateId),
                        MaxCount     = i.MaxCount,
                        MinCount     = i.MinCount
                    }).ToList()
                };

                uow.MonsterTemplates.Add(monsterTemplate);

                await uow.SaveChangesAsync();

                return(monsterTemplate);
            }
        }
예제 #9
0
 public async Task <IList <UserAccessToken> > GetUserAccessTokensAsync(int userId)
 {
     using (var uow = _unitOfWorkFactory.CreateUnitOfWork())
     {
         return(await uow.UserAccessTokenRepository.GetUserAccessTokensForUser(userId));
     }
 }
예제 #10
0
        public async Task <bool> AddRange(List <IAlternativeModel> alternatives)
        {
            var project = await _projectRepository.GetProjectByIdAsync(alternatives[0].ProjectId);

            project.Status      = 4;
            project.DateUpdated = DateTime.Now;
            var order = 1;

            foreach (var alter in alternatives)
            {
                alter.DateCreated = DateTime.Now;
                alter.DateUpdated = DateTime.Now;
                alter.Order       = order;
                order++;
                alter.AlternativeId = Guid.NewGuid();
            }

            using (var uow = _uowFactory.CreateUnitOfWork())
            {
                await _projectRepository.UpdateProject(project);

                await _alternativeRepository.AddRange(alternatives);

                uow.Commit();
            }

            return(true);
        }
예제 #11
0
 public async Task <EmployeeModel> GetEmployee(int id)
 {
     using (var unitOfWork = _unitOfWorkFactory.CreateUnitOfWork())
     {
         return(await _employeeDal.GetEmployee(unitOfWork, id));
     }
 }
예제 #12
0
        /// <summary>
        /// Create method,
        /// creates using UnitOfWork.
        /// <param name="entity">Model, type of generic.</param>
        /// </summary>
        public virtual async Task AddAsync(T entity)
        {
            var unitOfWork = uowFactory.CreateUnitOfWork();
            await unitOfWork.AddAsync(entity);

            await unitOfWork.CommitAsync();
        }
예제 #13
0
파일: Repository.cs 프로젝트: boriic/git222
        public async Task Insert(T entity)
        {
            var unitOfWork = uowFactory.CreateUnitOfWork();
            await unitOfWork.AddAsync <T>(entity);

            await unitOfWork.CommitAsync();
        }
예제 #14
0
        public async Task <ErrorValue> Add(sell_Offer entity)
        {
            using (var unitOfWork = _factory.CreateUnitOfWork())
            {
                try
                {
                    unitOfWork.StartTransaction();
                    NullProperties(entity);
                    var canAdd = await CanAddOffer(entity, unitOfWork);

                    if (canAdd == false)
                    {
                        return(ErrorValue.AmountGreaterThanStock);
                    }
                    unitOfWork.SellOfferRepository.Add(entity);
                    await unitOfWork.Save();

                    unitOfWork.Commit();
                }
                catch (Exception)
                {
                    unitOfWork.Rollback();
                    return(ErrorValue.ServerError);
                }
            }
            return(ErrorValue.NoError);
        }
예제 #15
0
        /// <summary>
        /// Creates a new master page.
        /// </summary>
        /// <param name="masterPage">New master page details.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        /// <returns>Newly allocated master page identifier.</returns>
        public long Create(MasterPage masterPage, IUnitOfWork unitOfWork = null)
        {
            IUnitOfWork localUnitOfWork = unitOfWork == null?_unitOfWorkFactory.CreateUnitOfWork() : null;

            try
            {
                IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork ?? localUnitOfWork);
                dbm.SetSQL(_sqlManager.GetSql("Sql.CreateMasterPage.sql"));
                dbm.AddParameter("@TenantId", FieldType.BigInt, masterPage.TenantId);
                AddMasterPageParameters(masterPage, dbm);
                dbm.AddOutputParameter("@MasterPageId", FieldType.BigInt);
                Dictionary <string, object> outputValues = new Dictionary <string, object>();
                dbm.ExecuteNonQuery(outputValues);
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Commit();
                }
                return((long)outputValues["@MasterPageId"]);
            }
            catch
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Rollback();
                }
                throw;
            }
            finally
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Dispose();
                }
            }
        }
예제 #16
0
        public async Task <ErrorValue> Add(product entity)
        {
            using (var unitOfWork = _factory.CreateUnitOfWork())
            {
                try
                {
                    unitOfWork.StartTransaction();
                    NullProperties(entity);
                    var result = await unitOfWork.ProductRepository.GetData(p => p.product_owner == entity.product_owner && p.Name == entity.Name);

                    if (result.Count() != 0)
                    {
                        return(ErrorValue.EntityExists);
                    }
                    unitOfWork.ProductRepository.Add(entity);
                    await unitOfWork.Save();

                    unitOfWork.Commit();
                }
                catch (Exception)
                {
                    unitOfWork.Rollback();
                    return(ErrorValue.ServerError);
                }
            }
            return(ErrorValue.NoError);
        }
예제 #17
0
 // GET: api/Trains
 public IEnumerable <TrainDTO> GetTrains()
 {
     using (var dbcontext = unitOfWorkFactory.CreateUnitOfWork())
     {
         return(Mapper.Map <IEnumerable <Train>, IEnumerable <TrainDTO> >(dbcontext.Trains));
     }
 }
        private void ProcessTaskCancelation(int currentServerId)
        {
            Queue <int> cancelQueueTasks = new Queue <int>();

            using (IUnitOfWork unitOfWork = unitOfWorkFactory.CreateUnitOfWork(contextSettings))
            {
                IDataRequest <TaskInfo> specification = new DataRequest <TaskInfo>(new TaskCancellationSpecification(currentServerId));
                //Retrieving tasks for cancellation...
                specification.Take = 10;
                ICollection <TaskInfo> tasks = taskRepository.GetBySpecification(specification);
                foreach (TaskInfo taskInfo in tasks)
                {
                    try
                    {
                        cancelQueueTasks.Enqueue(taskInfo.Id);
                    }
                    catch (Exception ex)
                    {
                        taskInfo.TaskState = TaskStates.Failed;
                        unitOfWork.Update(taskInfo);
                    }
                }
                if (cancelQueueTasks.Count > 0)
                {
                    unitOfWork.Commit();
                }
            }

            while (cancelQueueTasks.Count > 0)
            {
                int taskId = cancelQueueTasks.Dequeue();
                taskProcessing.CancelTask(taskId);
            }
        }
예제 #19
0
 public async Task <DependentModel> GetDependent(int id)
 {
     using (var unitOfWork = _unitOfWorkFactory.CreateUnitOfWork())
     {
         return(await _dependentDal.GetDependent(unitOfWork, id));
     }
 }
예제 #20
0
 public async Task <IList <ItemTemplateSection> > GetAllSectionsAsync()
 {
     using (var uow = _unitOfWorkFactory.CreateUnitOfWork())
     {
         return(await uow.ItemTemplateSections.GetAllWithCategoriesAsync());
     }
 }
 public async Task <ICollection <CategoryDto> > GetAllCategoriesAsync()
 {
     using (IUnitOfWork uow = unitOfWorkFactory.CreateUnitOfWork())
     {
         var categoryRepository = uow.GetRepository <ICategoryRepository>();
         return(this.mapper.Map <ICollection <CategoryDto> >(await categoryRepository.FindAndMapAsync(c => c)));
     }
 }
예제 #22
0
 public void Create(SportEntity entity)
 {
     using (var uow = unitOfWorkFactory.CreateUnitOfWork())
     {
         uow.SportRepository.Insert(entity);
         uow.Save();
     }
 }
예제 #23
0
        public async Task <WorkspaceModel> GetWorkspaceById(long workspaceId)
        {
            var unitOfWork = _unitOfWorkFactory.CreateUnitOfWork();

            var result = await _workspaceDAL.GetWorkspaceById(unitOfWork, workspaceId);

            return(result);
        }
예제 #24
0
 public void AddInstructor(InstructorGroupEntity entity)
 {
     using (var uow = unitOfWorkFactory.CreateUnitOfWork())
     {
         uow.InstructorGroupRepository.Insert(entity);
         uow.Save();
     }
 }
 public async Task <bool> CheckExistFavoriteUserModel(FavoriteModelDTO model)
 {
     using (var uof = unitOfWorkFactory.CreateUnitOfWork())
     {
         return(await uof.FavoriteModelRepository.
                CheckExistFavoriteUserModel(favoriteModelMapper.Map(model)));
     }
 }
예제 #26
0
        public async Task <IList <BrandDTO> > GetBrands()
        {
            using (var uof = unitOfWorkFactory.CreateUnitOfWork())
            {
                var result = await uof.BrandRepository.GetBrands();

                return(result.Select(brandMapper.Map).ToList());
            }
        }
예제 #27
0
        public async Task <IList <ModelDTO> > GetBrandModels(long brandId)
        {
            using (var uow = unitOfWorkFactory.CreateUnitOfWork())
            {
                var result = await uow.ModelRepository.GetBrandModels(brandId);

                return(result.Select(modelMapper.Map).ToList());
            }
        }
예제 #28
0
        public ActionResult Index()
        {
            SearchViewModel search = new SearchViewModel();

            search.Stations         = unitOfFactory.CreateUnitOfWork().Routes.Select(r => r.To).Distinct().ToList();
            search.ConnectionPaths  = new List <ConnectionPath>();
            search.SearchParameters = new SearchParameters();
            return(View(search));
        }
예제 #29
0
        public Store GetStore(int id)
        {
            var store = new Store();

            using (var unitOfWork = _unitOfWorkFactory.CreateUnitOfWork())
            {
                store = unitOfWork.Stores.Find(id);
            }

            return(store);
        }
예제 #30
0
        public async Task <IEnumerable <Product> > GetProducts(string name = "")
        {
            using (var unitOfWork = _unitOfWorkFactory.CreateUnitOfWork())
            {
                var products = string.IsNullOrEmpty(name)
                    ? await unitOfWork.ProductRepository.GetAll()
                    : await unitOfWork.ProductRepository.GetProductsByName(name);

                return(products);
            }
        }