Exemple #1
0
        public IHttpActionResult Get()
        {
            var drinks = UnitOfWork.Drinks.GetAll();
            var models = _modelFactory.Create(drinks);

            return(Ok(models));
        }
        public RecruitmentInformationDto GetRecruitmentInfoById(int id)
        {
            RecruitmentInformation recruitmentInformation =
                _context.RecruitmentInformations.FirstOrDefault(rec => rec.Id.Equals(id));

            return(_modelFactory.Create(recruitmentInformation));
        }
Exemple #3
0
 public void CreateTestWhenEachModelIsAvailable()
 {
     foreach (var modelType in modelTypes)
     {
         var actual = modelFactory.Create(modelType, DateTime.Now);
         Assert.IsNotNull(actual);
     }
 }
Exemple #4
0
        public IHttpActionResult Get(int id)
        {
            try {
                var team  = _service.Teams.Get(id);
                var model = _modelFactory.Create(team);

                return(Ok(model));
            } catch (Exception ex) {
                return(InternalServerError(ex));
            }
        }
Exemple #5
0
        public List <TodoListDto> GetTodoListsForUser(int ownerId)
        {
            var todoListEntities = _context.TodoLists.Where(x => x.OwnerId == ownerId).Include(y => y.Tasks).ToList();

            var todoLists = new List <TodoListDto>();

            foreach (var list in todoListEntities)
            {
                todoLists.Add(_todoListModelFactory.Create(list));
            }

            return(todoLists);
        }
Exemple #6
0
        public ActionResult List(string query = null)
        {
            if (!string.IsNullOrWhiteSpace(query))
            {
                var userid      = User.Identity.GetUserId();
                var currentUser = _userService.GetUserById(userid);
                var users       = _userService.GetUsersByQuery(query);

                return(View(_modelFactory.Create(currentUser, users)));
            }

            return(View(_modelFactory.Create()));
        }
Exemple #7
0
 public void NewOrder(Guid id)
 {
     try
     {
         var order = UnitOfWork.Orders.Get(id);
         var model = _modelFactory.Create(order);
         Clients.Group("JackBlack").newOrder(model);
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine("No order");
         Clients.Caller.error("Server error occured when finding order");
     }
 }
Exemple #8
0
 public IHttpActionResult Get(int id)
 {
     try
     {
         var lPlayer = _lService.Players.Get(id);
         var lModel  = _lModelFactory.Create(lPlayer);
         return(Ok(lModel));
     }//end try
     catch (Exception lError)
     {
         //Logging
         return(InternalServerError(lError));
     }//end catch
 }
        public IHttpActionResult Get(int id)
        {
            try {
                var player = _service.Players.Get(id);
                var model  = _modelFactory.Create(player);

                return(Ok(model));
            } catch (Exception ex) {
                //Logging
#if DEBUG
                return(InternalServerError(ex));
#endif
                return(InternalServerError( ));
            }
        }
Exemple #10
0
        /// <summary>
        /// Executes the add user command.
        /// </summary>
        public virtual void ExecuteAddResource()
        {
            NavigationParameters parameters = new NavigationParameters();

            parameters.Add(NavigationParameterNames.Ressource, SelectedResource ?? _resourceFactory.Create());
            _regionManager.RequestNavigate(Constants.Regions.MainRegion, new Uri(Constants.ViewNames.CreateResource, UriKind.Relative), parameters);
        }
Exemple #11
0
        private void OpenEditDialog(IUserModel user)
        {
            NavigationParameters parameters = new NavigationParameters();

            parameters.Add(NavigationParameterNames.User, user ?? _userFactory.Create());
            _regionManager.RequestNavigate(Constants.Regions.MainRegion, new Uri(Constants.ViewNames.CreateUserView, UriKind.Relative), parameters);
        }
Exemple #12
0
        public IQueryable <StoryModel> GetStories(int page, string titleFilter, int[] genreFilters, int pageSize = 10)
        {
            var stories = dbContext.Stories;
            var result  = stories.Select(t => t);

            if (titleFilter != null)
            {
                result = result.Where(t => t.Title.StartsWith(titleFilter));
            }

            if (genreFilters != null)
            {
                result = result.Where(t => t.Genres.Any(g => genreFilters.Contains(g.ID)));
            }

            return(result.Skip(page * pageSize).Take(pageSize).Select(t => mFactory.Create(t)));
        }
        public GenericActionResult <RoleReturnModel> GetRoleById(string id)
        {
            var role = this.FindById(id);

            if (role != null)
            {
                return new GenericActionResult <RoleReturnModel> {
                           Result = _modelFactory.Create(role), IsSuccess = true, Errors = null
                }
            }
            ;
            else
            {
                return new GenericActionResult <RoleReturnModel> {
                           Result = null, IsSuccess = false, Errors = new List <string> {
                               "Role not found"
                           }
                }
            };
        }
Exemple #14
0
        /// <summary>
        /// Called when [navigated to].
        /// </summary>
        /// <param name="navigationContext">The navigation context.</param>
        public override void OnNavigatedTo(NavigationContext navigationContext)
        {
            IUserModel userModel = navigationContext.Parameters[NavigationParameterNames.User] as IUserModel;

            if (userModel == null)
            {
                userModel      = _userFactory.Create();
                userModel.Role = _roleFactory.Create();
            }

            UserModel = userModel;
            _okCommand.RaiseCanExecuteChanged();
        }
Exemple #15
0
        public IHttpActionResult details(int id)
        {
            try {
                var ads   = _annonceRepository.GetById(id);
                var model = _modelFactory.Create(ads);

                return(Ok(model));
            }
            catch (Exception ex)
            {
                //Logging
                return(InternalServerError(ex));
            }
        }
        /// <summary>
        /// Gets a model class instance from the specified type bound to the specified sourceItem.
        /// </summary>
        /// <param name="typeName">The name of the type.</param>
        /// <param name="model">The model reference as provided by the rendering information.</param>
        /// <param name="sourceItem">The source item to bind to the model class instance.</param>
        /// <param name="throwOnTypeCreationError">if set to <c>true</c> an error will be thrown if the model class cannot be instantiated.</param>
        /// <returns>New instance of the model class specified by the typeName parameter bound to the specified sourceItem.</returns>
        /// <exception cref="System.InvalidOperationException">Could not locate type '{typeName}'. Model reference: '{model}'</exception>
        protected Object GetModelFromTypeName(String typeName, String model, Item sourceItem, Boolean throwOnTypeCreationError)
        {
            Type type = TypeHelper.GetType(typeName);

            if (type == null)
            {
                if (throwOnTypeCreationError)
                {
                    throw new InvalidOperationException("Could not locate type '{0}'. Model reference: '{1}'".FormatWith(new object[] { typeName, model }));
                }
                return(null);
            }

            IModelFactory modelFactory = GetModelFactory(type);

            return(modelFactory.BindingContract.IsCompliant(sourceItem, type) ? modelFactory.Create(sourceItem, type) : null);
        }
Exemple #17
0
        private ItemModel CreateItemModel(Item innerItem, string defaultLanguage, bool includeStandardTemplateFields, bool includeMetaData, bool enrich = true, bool includeEditMode = false)
        {
            if (innerItem == null)
            {
                return(null);
            }
            var model = _modelFactory.Create(innerItem, new GetRequestOptions()
            {
                Fields          = new string[0],
                IncludeMetadata = includeMetaData,
                IncludeStandardTemplateFields = includeStandardTemplateFields
            });

            if (enrich)
            {
                ItemModelActionFilter.EnrichItemModel(model, defaultLanguage, includeEditMode);
            }
            return(model);
        }
Exemple #18
0
        public OrderAdminDetailModel GetOrderDetails(Guid orderId)
        {
            var result = (from o in Context.Orders
                          join bc in Context.BasketContents on o.Id equals bc.Order.Id
                          join u in Context.Users on o.User.Id equals u.Id
                          join d in Context.Drinks on bc.Drink.Id equals d.Id
                          where o.Id == orderId
                          select new
            {
                UserId = u.Id,
                UserProfile = u.ProfilePhoto,
                OrderId = o.Id,
                o.OrderNumber,
                o.OrderWord,
                o.Completed,
                Drink = d
            }
                          );

            var drinks = new List <DrinkModel>();

            foreach (var row in result)
            {
                var drinkModel = _modelFactory.Create(row.Drink);
                drinks.Add(drinkModel);
            }
            var single = result.First();
            var model  = new OrderAdminDetailModel
            {
                OrderId        = single.OrderId,
                UserId         = single.UserId,
                UserProfile    = single.UserProfile,
                OrderNumber    = single.OrderNumber,
                OrderWord      = single.OrderWord,
                OrderCompleted = single.Completed,
                Drinks         = drinks.ToList()
            };

            return(model);
        }
Exemple #19
0
        public void Merge(string inputDacpacFileName, string databaseSource, string databaseName, IEnumerable <string> databaseSchemas = null, string schemaOwnerUser = null, string outputDacpacFileName = null)
        {
            var schemas = databaseSchemas as string[] ?? databaseSchemas?.ToArray() ?? new string[] { };

            using (var package = _packageFactory.Create(inputDacpacFileName))
            {
                var deploySchemas = schemas.Any() ? schemas.Select(s => s.Trim('[', ']')).ToList() : package.Model.Schemas.ToList();

                _logger.Information("Deploying Database Schemas {@Schemas}", deploySchemas);

                using (var databaseModel = _modelFactory.Create(databaseSource, databaseName))
                {
                    var deployObjects = package.Model.GetObjects(deploySchemas, true).ToArray();

                    var deployNames = deployObjects
                                      .Union(databaseModel.GetObjects(deploySchemas, false))
                                      .Where(o => o.Name.HasName)
                                      .Select(o => o.Name.ToString())
                                      .Distinct();

                    databaseModel.Remove(deployNames);

                    if (!schemaOwnerUser.NullOrEmpty() && databaseModel.GetUser(schemaOwnerUser) == null)
                    {
                        databaseModel.AddUser(schemaOwnerUser);
                    }

                    databaseModel.AddObjects(deployObjects, schemaOwnerUser);

                    package.Model = databaseModel;

                    var fileName = outputDacpacFileName ?? inputDacpacFileName;

                    package.Save(fileName);

                    _logger.Information("New Data-tier Application Package file saved {FileName}", fileName);
                }
            }
        }
Exemple #20
0
        public CarBase Create(Type modelType, string number, Color color, State state, DateTime modelCreation)
        {
            if (number.IsNullOrEmpty())
            {
                throw new ArgumentNullException("Car number must be init.");
            }

            if (!Regex.IsMatch(number, carNumberPattern))
            {
                throw new ArgumentException("Incorrect car number format.");
            }

            var model = modelFactory.Create(modelType, modelCreation);
            var make  = makeFactory.Create(model.MakeType);

            return(new CarBase
            {
                Number = number,
                Make = make,
                Color = color,
                Model = model,
                State = state
            });
        }
Exemple #21
0
        public GenericActionResult <UserReturnModel> CreateUser(CreateUserBindingModel user, string password)
        {
            var newUser = new ApplicationUser()
            {
                UserName    = user.Username,
                Email       = user.Email,
                FirstName   = user.FirstName,
                LastName    = user.LastName,
                PhoneNumber = user.MobileNumber,
            };

            try
            {
                IdentityResult addUserResult = this.Create(newUser, password);

                var result = new GenericActionResult <UserReturnModel>()
                {
                    IsSuccess = addUserResult.Succeeded,
                    Errors    = addUserResult.Errors,
                    Result    = addUserResult.Succeeded ? _modelFactory.Create(newUser) : null
                };

                return(result);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Creating user failed!");

                return(new GenericActionResult <UserReturnModel>()
                {
                    Errors = new List <string>()
                    {
                        "An error occured while creating the user,please try again later."
                    },
                    IsSuccess = false,
                    Result = null
                });
            }
        }
Exemple #22
0
 /// <summary>
 /// Create a model class T instance and bind the specified item to the instance.
 /// </summary>
 /// <typeparam name="T">The model class that the item should be bound to.</typeparam>
 /// <param name="item">The item to bind.</param>
 /// <param name="modelFactory">The model factory to use.</param>
 /// <returns>A new instance of the model class T bound to the specified item.</returns>
 /// <exception cref="System.Exception">This method calls the model factory and the associated binding contract that may throw an error if the item does not comply with the binding contract or if the model class does not contain a constructor that accepts an item.</exception>
 public static T BindAs <T>(this Item item, IModelFactory modelFactory) where T : class
 {
     return(modelFactory.Create <T>(item));
 }
Exemple #23
0
 Ticket CreateModel()
 {
     return(modelFactory.Create <Ticket>());
 }
        public IModel Generate(int n, int d)
        {
            var nodes = BuildConnections(GenerateNodes(n), d);

            return(modelFactory.Create(nodes));
        }
Exemple #25
0
 public IModelObject Create(ushort id, ushort tid, ushort parentid)
 {
     repository.Add(factory.Create(id, tid, parentid));
     return(repository.Get(id));
 }
Exemple #26
0
        public TaskDto GetTaskById(int id)
        {
            Task task = _context.Tasks.FirstOrDefault(rec => rec.Id.Equals(id));

            return(_taskModelFactory.Create(task));
        }
        public virtual async Task <bool> Create(TModel model)
        {
            model = this.InitializeModelForCreate(model);

            return(await factory.Create(model));
        }
Exemple #28
0
 // GET api/humans
 public IHttpActionResult Get() => Ok(_apiBackend.GetHumans().Values.Select(human => _modelFactory.Create(human)));
Exemple #29
0
        public IHttpActionResult CreateOrder(OrderModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            User currentUser = UserManager.FindById(User.Identity.GetUserId());

            if (currentUser == null)
            {
                return(InternalServerError());
            }


            List <Drink> drinks = new List <Drink>();

            drinks.AddRange(model.Drinks.Select(drink => UnitOfWork.Drinks.Get(drink.Id)));
            if (drinks.Contains(null))
            {
                return(BadRequest());
            }


            //Bit of a bad way to auto increment ordernumber
            var lastOrderNumber = UnitOfWork.Orders.GetPreviousOrder().OrderNumber + 1;


            //Only way i can think to store OrderCompletedTime before it is completed is to
            //set it to max value, anything greater than todays date is not complete.
            //Cant use nulls in datetime type
            var order = new Order
            {
                Id = Guid.NewGuid(),
                CreatedDateTime    = DateTime.Now,
                UpdatedDateTime    = DateTime.Now,
                OrderCompletedTime = DateTime.MaxValue,
                OrderNumber        = lastOrderNumber,
                OrderWord          = "Humorous",
                TotalCost          = drinks.Sum(drink => drink.Price),
                Paid      = false,
                Completed = false,
                User      = currentUser
            };

            UnitOfWork.Orders.Add(order);

            var stripeCharge = CreateStripeCharge(order, model.Token);

            if (stripeCharge == "succeeded")
            {
                order.Paid            = true;
                order.UpdatedDateTime = DateTime.Now;
            }

            List <BasketContents> basket = new List <BasketContents>();

            basket.AddRange(drinks.Select(drink => new BasketContents
            {
                Id              = Guid.NewGuid(),
                Drink           = drink,
                Order           = order,
                CreatedDateTime = DateTime.Now,
                UpdatedDateTime = DateTime.Now
            }));

            UnitOfWork.BasketContents.AddRange(basket);

            if (UnitOfWork.Save() == 0)
            {
                return(InternalServerError());
            }

            var orderModel = _modelFactory.Create(stripeCharge, order.OrderWord, order.OrderNumber, order.Id);

            return(Ok(orderModel));
        }