Beispiel #1
0
        public IActionResult Index()
        {
            var lstPieDto = _unitOfWork.PieBs.GetAll();
            var lstPieVm  = Transformation.Convert <PieDto, PieVM>(lstPieDto);

            return(View(lstPieVm));
        }
Beispiel #2
0
        public IActionResult PieOfTheWeek()
        {
            var lstPieDto = _unitOfWork.PieBs.FindBy(x => x.IsPieOfTheWeek == true);
            var lstPieVm  = Transformation.Convert <PieDto, PieVM>(lstPieDto);

            return(View("Index", lstPieVm));
        }
Beispiel #3
0
        public IEnumerable <PieVM> LoadMorePies(int skipCount, int takeCount)
        {
            var dbPies   = _unitOfWork.PieBs.GetAll().Skip(skipCount).Take(takeCount);
            var lstPieVm = Transformation.Convert <PieDto, PieVM>(dbPies);

            return(lstPieVm);
        }
Beispiel #4
0
        /// <summary>
        /// Saves the context into the database and returns the modified data.
        /// </summary>
        /// <returns>Returns the modified data in Data Transfer Objects.</returns>
        public IEnumerable <T> Save()
        {
            var modifiedEntities = AppDbContext.ChangeTracker.Entries <E>().Where(x => x.State == EntityState.Modified);

            AppDbContext.SaveChanges();
            var      savedEntities = AppDbContext.ChangeTracker.Entries <E>();
            List <T> lstT          = (List <T>)Transformation.Convert <E, T>(modifiedEntities.Select(x => x.Entity).ToList());

            return(lstT);
        }
Beispiel #5
0
 public IActionResult Edit(PieVM PieVm)
 {
     if (ModelState.IsValid)
     {
         var PieDto = Transformation.Convert <PieVM, PieDto>(PieVm);
         _unitOfWork.PieBs.Edit(PieDto);
         _unitOfWork.Commit();
         return(View("Index"));
     }
     return(View(PieVm));
 }
Beispiel #6
0
        public async Task <IActionResult> Edit(string id)
        {
            var user = await _userManagementBs.GetById(id);

            if (user == null)
            {
                return(RedirectToAction("UserManagement", _userManagementBs.Users()));
            }
            var editUserVm = Transformation.Convert <IdentityUser, EditUserVM>(user);

            return(View("_Edit", editUserVm));
        }
Beispiel #7
0
        public IActionResult Details(Guid id)
        {
            var pieDto = _unitOfWork.PieBs.GetById(id);

            if (pieDto == null)
            {
                return(NotFound());
            }
            var pieVm = Transformation.Convert <PieDto, PieVM>(pieDto);

            return(View(pieVm));
        }
Beispiel #8
0
        private void UpdateRobot2UI(object sender, OptiTrack.FrameReceivedEventArgs args)
        {
            var robot2BasePosition = robot2Transformation.Convert(args.BallPosition);

            robot2PositionChart.Update(new double[] {
                robot2BasePosition[0], robot2BasePosition[1], robot2BasePosition[2]
            });
            Dispatcher.Invoke(() => {
                robot2BaseActualPositionX.Text = robot2BasePosition[0].ToString("F3");
                robot2BaseActualPositionY.Text = robot2BasePosition[1].ToString("F3");
                robot2BaseActualPositionZ.Text = robot2BasePosition[2].ToString("F3");
            });
        }
Beispiel #9
0
        /// <summary>
        /// Predicate is for defining conditions.FindBy function converts predicate from Data Tranfer Object to Domain Model Object.
        /// </summary>
        /// <param name="predicateDt">The searching condition.</param>
        /// <returns>Returns the list of Data Transfer Objects that fits to the condition.</returns>
        public virtual IEnumerable <T> FindBy(Expression <Func <T, bool> > predicateDt)
        {
            //Converting predicate expression from T type to E type
            var param     = Expression.Parameter(typeof(E));
            var visitor   = new Visitor <T, E>(param);
            var body      = visitor.Visit(predicateDt.Body);
            var predicate = Expression.Lambda <Func <E, bool> >(body, param);
            //
            var             query = AppDbContext.Set <E>().Where(predicate);
            IEnumerable <T> lstT  = (List <T>)Transformation.Convert <E, T>(query);

            return(lstT);
        }
Beispiel #10
0
        /// <summary>
        /// Deletion means changing status field value from true to false.
        /// </summary>
        /// <param name="baseDt">The data transfer object that should be deleted.</param>
        /// <returns>Returns the deleted object.</returns>
        public virtual T Delete(T baseDt)
        {
            if ((baseDt = GetById(baseDt.Id)) == null)
            {
                throw new Exception("There is no item!");
            }
            baseDt.ModifiedDate = DateTime.Now;
            baseDt.Status       = false;
            var entityE      = Transformation.Convert <T, E>((T)baseDt);
            var entityFromDB = AppDbContext.Set <E>().Find(new object[] { baseDt.Id });

            AppDbContext.Entry(entityFromDB).CurrentValues.SetValues(entityE);
            return(baseDt);
        }
Beispiel #11
0
        public IActionResult Index()
        {
            var items = _unitOfWork.ShoppingCartBs.GetShoppingCartItems();

            _unitOfWork.ShoppingCartBs.ShoppingCartItems = items;
            ShoppingCartVM shoppingCartVm = new ShoppingCartVM()
            {
                LstShoppingCartVm = (List <ShoppingCartItemVM>)Transformation.Convert <ShoppingCartItemDto, ShoppingCartItemVM>(_unitOfWork.ShoppingCartBs.GetShoppingCartItems()),
                Total             = _unitOfWork.ShoppingCartBs.GetShoppingCartTotal()
            };

            AssignViewBags();
            return(View(shoppingCartVm));
        }
        public async Task <IActionResult> Register(LoginVM loginVm)
        {
            if (ModelState.IsValid)
            {
                var identityUser = Transformation.Convert <LoginVM, IdentityUser>(loginVm);
                var result       = await _userManagementBs.Register(identityUser, loginVm.Password);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View(loginVm));
        }
Beispiel #13
0
        /// <summary>
        /// Modifing given data to the context.
        /// During modifing some fields are changed as
        /// The status is changed to true.
        /// ModifiedDate are assigned as DateTime.Now.
        /// </summary>
        /// <param name="baseDt"> The object which is added into the context</param>
        public virtual void Edit(T baseDt)
        {
            T currentBaseDt = GetById(baseDt.Id);

            if (currentBaseDt == null)
            {
                throw new Exception("There is no item!");
            }
            baseDt.Status       = true;
            baseDt.ModifiedDate = DateTime.Now;
            baseDt.CreatedDate  = currentBaseDt.CreatedDate;
            var entityE      = Transformation.Convert <T, E>((T)baseDt);
            var entityFromDB = AppDbContext.Set <E>().Find(new object[] { baseDt.Id });

            AppDbContext.Entry(entityFromDB).CurrentValues.SetValues(entityE);
        }
Beispiel #14
0
        public IViewComponentResult Invoke()
        {
            var items = _shoppingCartBs.GetShoppingCartItems();

            items = new List <ShoppingCartItemDto>()
            {
                new ShoppingCartItemDto(), new ShoppingCartItemDto()
            };
            var shoppingCartVm = new ShoppingCartVM()
            {
                Total             = _shoppingCartBs.GetShoppingCartTotal(),
                LstShoppingCartVm = (List <ShoppingCartItemVM>)Transformation.Convert <ShoppingCartItemDto, ShoppingCartItemVM>(_shoppingCartBs.GetShoppingCartItems())
            };

            return(View(shoppingCartVm));
        }
Beispiel #15
0
        /// <summary>
        /// Adding given data to the context.
        /// During adding some fields are changed as
        /// The status is changed to true.
        /// CreationDate and ModifiedDate are assigned as DateTime.Now.
        /// </summary>
        /// <param name="baseDt"> The object which is added into the context</param>
        public virtual void Add(T baseDt)
        {
            if (AppDbContext == null)
            {
                return;
            }

            baseDt.Status       = true;
            baseDt.CreatedDate  = DateTime.Now;
            baseDt.ModifiedDate = DateTime.Now;
            var entityE = Transformation.Convert <T, E>(baseDt);

            if (AppDbContext.Set <E>() != null)
            {
                AppDbContext.Set <E>().Add(entityE);
            }
        }
Beispiel #16
0
        public IActionResult Checkout(OrderVM orderVm)
        {
            if (_unitOfWork.ShoppingCartBs.ShoppingCartItems.Count() == 0)
            {
                ModelState.AddModelError("", "Your cart is empty, add some pies first");
            }

            if (ModelState.IsValid)
            {
                var orderDto = Transformation.Convert <OrderVM, OrderDto>(orderVm);
                _unitOfWork.OrderBs.CreateOrder(orderDto, _unitOfWork.ShoppingCartBs);
                _unitOfWork.ShoppingCartBs.ClearCart();
                _unitOfWork.Commit();
                return(RedirectToAction("CheckoutComplete"));
            }
            return(View(orderVm));
        }
Beispiel #17
0
        public async Task <IActionResult> Edit(EditUserVM editUserVm)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("_Edit", editUserVm));
            }

            var identityUser = Transformation.Convert <EditUserVM, IdentityUser>(editUserVm);
            var result       = await _userManagementBs.Edit(identityUser);

            if (result.Succeeded)
            {
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "User not updated, something went wrong.");

            return(View("_Edit", editUserVm));
        }
Beispiel #18
0
        public async Task <IActionResult> Add(UserVM userVm)
        {
            if (!ModelState.IsValid)
            {
                return(View(userVm));
            }

            var            identityUser = Transformation.Convert <UserVM, IdentityUser>(userVm);
            IdentityResult result       = await _userManagementBs.Register(identityUser, userVm.Password);

            if (result.Succeeded)
            {
                return(RedirectToAction("Index"));
            }

            foreach (IdentityError error in result.Errors)
            {
                ModelState.AddModelError("", error.Description);
            }
            return(View("_Add", userVm));
        }