Beispiel #1
0
        /// <summary>
        /// Methode called when user generate and Index_QR entity,
        /// It takes the ProuctID and COntroller and action name those are passed by the view
        /// looks for its entities in the DB and create a new Index_QR entity with
        /// composed of those entites and also includes the User entity who was logged in
        /// </summary>
        /// <param name="productID">Product of ID to generate</param>
        /// <param name="controllerName">Name of controller, so the ID can be found</param>
        /// <param name="actionName">Name of the action, so the ID can be found</param>
        /// <returns>In case of insert query success it return the same page with the new generated QR
        ///  in case of fail it return an error page</returns>

        public ActionResult Create(long productID, string controllerName, string actionName)
        {
            try
            {
                Controller_QR controller_QR = _unityOfWork.Controller_QR.GetAll().FirstOrDefault(b => b.Name == controllerName);
                Action_QR     action_QR     = _unityOfWork.Action_QR.GetAll().FirstOrDefault(b => b.Name == actionName);
                Product       Product       = _unityOfWork.Product.GetById(productID);
                Index_QR      model         = new Index_QR()
                {
                    Product       = Product,
                    Controller_QR = controller_QR,
                    Action_QR     = action_QR,
                    //ProductID = productID,
                    // ControllerID = controller_QR.ID,
                    UserID   = User.FindFirst(ClaimTypes.NameIdentifier).Value,
                    Created  = DateTime.Now,
                    IsActive = true
                };

                _unityOfWork.Index_QR.Insert(model);
                _unityOfWork.Save();

                return(RedirectToAction("Detail", "Product", new { id = productID }));
            }
            catch
            {
                return(RedirectToAction("Error", "Home"));
            }
        }
Beispiel #2
0
        public IActionResult Details(string stripeToken)
        {
            OrderHeader orderHeader = _unitOfWork.OrderHeader.GetFirstOrDefault(u => u.Id == OrderVM.OrderHeader.Id, includeProperties: "ApplicationUser");

            if (stripeToken != null)
            {
                //process payment
                var options = new ChargeCreateOptions
                {
                    Amount      = Convert.ToInt32(orderHeader.OrderTotal * 100),
                    Currency    = "usd",
                    Description = "Order ID: " + orderHeader.Id,
                    Source      = stripeToken
                };

                var    service = new ChargeService();
                Charge charge  = service.Create(options);

                if (charge.BalanceTransactionId == null)
                {
                    orderHeader.PaymentStatus = SD.PaymentStatusRejected;
                }
                else
                {
                    orderHeader.TransactionId = charge.BalanceTransactionId;
                }
                if (charge.Status.ToLower() == "succeeded")
                {
                    orderHeader.PaymentStatus = SD.PaymentStatusApproved;
                    orderHeader.PaymentDate   = DateTime.Now;
                }
                _unitOfWork.Save();
            }
            return(RedirectToAction("Details", "Order", new { id = orderHeader.Id }));
        }
Beispiel #3
0
        public ActionResult Edit(CreateProductHistoryViewModel model)
        {
            var            productHistoryToUpdate = new ProductHistory();
            ProductHistory newProductHistory      = new ProductHistory()
            {
                ProductID = model.ProductID,
                HistoryID = model.HistoryID,
                Comment   = model.Comment,
                Date      = model.DateTimeNow,
                UserID    = model.Email
            };
            var  product = _unityOfWork.Product.getProductWithHistory(model.ProductID);
            long id      = product.ID;

            // find history entry in list of histories
            foreach (var productHistory in product.ProductHistories)
            {
                // a unique history entry is given by ProductID, HistoryID, Date
                if (productHistory.Date.ToString() == model.DateTimeNow.ToString() && model.OldHistoryID == productHistory.HistoryID && model.Email == productHistory.UserID)
                {
                    productHistoryToUpdate = productHistory;
                    break;
                }
            }
            product.ProductHistories.Remove(productHistoryToUpdate);
            product.ProductHistories.Add(newProductHistory);
            _unityOfWork.Product.Update(product);
            _unityOfWork.Save();
            newProductHistory.User   = null;
            newProductHistory.UserID = null;
            LoggingController.writeLog(newProductHistory, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString());
            return(RedirectToAction("Details", new { id = id }));
        }
Beispiel #4
0
        public IActionResult Create(ProjectModel project)
        {
            _unityOfWork.Project.Insert(project);
            _unityOfWork.Save();
            LoggingController.writeLog(project, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString());

            return(RedirectToAction("Index"));
        }
Beispiel #5
0
        public void Insert(SubscriptionDTO subscription)
        {
            var subscriptionModel = ConvertToModel(subscription);

            subscriptionModel.Enabled = true;
            _subscriptionRepository.Insert(subscriptionModel);

            _unityOfWork.Save();
        }
Beispiel #6
0
        public void Insert(UserDTO user)
        {
            var model = ConvertToModel(user);

            model.Enabled = true;

            _userRepository.Insert(model);

            _unityOfWork.Save();
        }
Beispiel #7
0
        public void Add()
        {
            var entity = new EntityTest();

            _genericRepository.Add(entity);

            _unityOfWork.Save();

            _entityTestRepository.Delete(entity);

            _unityOfWork.Save();

            //
        }
Beispiel #8
0
        public ActionResult Create(History history)
        {
            try
            {
                _unityOfWork.History.Insert(history);
                _unityOfWork.Save();
                return(RedirectToAction("Index", "History"));

                LoggingController.writeLog(history, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString());
            }
            catch
            {
                return(View());
            }
        }
Beispiel #9
0
        public void Execute(MotivoBloqueoInsertDto dto)
        {
            var registro = _mapper.Map <MotivoBloqueoInsertDto, MotivoBloqueo>(dto);

            _context.MotivosBloqueo.Add(registro);
            _context.Save();
        }
Beispiel #10
0
        public void Execute(UniversoInsertDto dto)
        {
            var registro = _mapper.Map <UniversoInsertDto, Universo>(dto);

            _context.Universos.Add(registro);
            _context.Save();
        }
 public IActionResult Edit(UserModel model)
 {
     if (ModelState.IsValid)
     {
         var steamId = UInt64.Parse(User.Claims.First().Value.Split("id/")[2]);
         var user    = _unityOfWork.GetRepository <User>().Query(x => x.SteamId == steamId).FirstOrDefault();
         user.Name = model.Name;
         if (model.PictureFile != null)
         {
             if (model.PictureFile.Length > 0)
             {
                 using (var ms = new MemoryStream())
                 {
                     model.PictureFile.CopyTo(ms);
                     var fileBytes = ms.ToArray();
                     _blobService.SelectBlobContainer(steamId.ToString());
                     var url = _blobService.UploadFile(fileBytes, model.PictureFile.FileName);
                     user.ProfilePicture = url;
                 }
             }
         }
         _unityOfWork.Save();
         return(Redirect("/Profile"));
     }
     return(View(model));
 }
Beispiel #12
0
        public void Execute(AreaInsertDto dto)
        {
            var registro = _mapper.Map <AreaInsertDto, Area>(dto);

            _context.Areas.Add(registro);
            _context.Save();
        }
        public void Execute(EstadoPerfilInsertDto dto)
        {
            var registro = _mapper.Map <EstadoPerfilInsertDto, EstadoPerfil>(dto);

            _context.EstadoPerfiles.Add(registro);
            _context.Save();
        }
Beispiel #14
0
        public void Execute(FiltroInsertDto dto)
        {
            var registro = _mapper.Map <FiltroInsertDto, Filtro>(dto);

            _context.Filtros.Add(registro);
            _context.Save();
        }
Beispiel #15
0
        public void Execute(CargoInsertDto dto)
        {
            var registro = _mapper.Map <CargoInsertDto, Cargo>(dto);

            _context.Cargos.Add(registro);
            _context.Save();
        }
Beispiel #16
0
        public async Task <IActionResult> Post([FromForm] ImagesGos obj)
        {
            IActionResult result  = Forbid();
            var           arquivo = Request.Form.Files[0];

            obj.Imagego     = unityOfWork.ImagesGoRepository.Imago(arquivo, "arch");
            obj.Description = Request.Form["Description"];

            try
            {
                if (obj.Imagego == null)
                {
                    return(result);
                }

                await unityOfWork.ImagesGoRepository.Post(obj);

                unityOfWork.Save();
                return(StatusCode(201));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message.ToString()));
            }
        }
Beispiel #17
0
        public void Execute(TipoPerfilInsertDto dto)
        {
            var registro = _mapper.Map <TipoPerfilInsertDto, TipoPerfil>(dto);

            _context.TiposPerfil.Add(registro);
            _context.Save();
        }
Beispiel #18
0
 public IActionResult Upsert(Company company)
 {
     if (ModelState.IsValid)
     {
         if (company.Id == 0)
         {
             _unityOfWork.Company.Add(company);
         }
         else
         {
             _unityOfWork.Company.Update(company);
         }
         _unityOfWork.Save();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(company));
 }
Beispiel #19
0
 public async Task <IActionResult> Upsert(Category category)
 {
     if (ModelState.IsValid)
     {
         if (category.Id == 0)
         {
             await _unitOfWork.Category.AddAsync(category);
         }
         else
         {
             _unitOfWork.Category.Update(category);
         }
         _unitOfWork.Save();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(category));
 }
Beispiel #20
0
        public void Execute(ref PerfilInserDto dto)
        {
            var registro = _mapper.Map <PerfilInserDto, Perfil>(dto);

            _context.Perfiles.Add(registro);
            _context.Save();

            dto.Id = registro.Id;
        }
Beispiel #21
0
        private User AddUser(ulong steamId)
        {
            var user = new User();
            var url  = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=" +
                       Configuration["SteamApiKey"] + "&steamids=" + steamId.ToString();
            var httpClient   = new HttpClient();
            var httpResponse = httpClient.GetAsync(url).Result;
            var userData     = JObject.Parse(httpResponse.Content.ReadAsStringAsync().Result)["response"];
            var userPlayers  = userData["players"].ToArray().First();

            user.Name           = userPlayers["personaname"].Value <string>();
            user.ProfilePicture = userPlayers["avatarfull"].Value <string>();
            user.SteamId        = steamId;
            _unityOfWork.GetRepository <User>().Add(user);
            _unityOfWork.Save();
            user = _unityOfWork.GetRepository <User>().GetByIdAsNoTracking(user.Id);
            return(user);
        }
Beispiel #22
0
        public IActionResult Create(CreateAttributeViewModel vm)
        {
            try
            {
                var model = _mapper.Map <Attribute>(vm);
                _unityOfWork.Attribute.Insert(model);
                _unityOfWork.Save();

                return(RedirectToAction("Index", "Attribute"));
            }
            catch
            {
                return(View());
            }
            //_db.Attribute.Add(attribute);
            //_db.SaveChanges();
            //return RedirectToAction("Index");
            //return View("Index");
        }
Beispiel #23
0
        public IActionResult Plus(int cartId)
        {
            var cart = _unitOfWork.ShoppingCart.GetFirstOrDefault(c => c.Id == cartId, includeProperties: "Product");

            cart.Count += 1;
            cart.Price  = SD.GetPriceBasedOnQuantity(cart.Count, cart.Product.Price, cart.Product.Price50, cart.Product.Price100);
            _unitOfWork.Save();
            return(RedirectToAction(nameof(Index)));
        }
Beispiel #24
0
 public IActionResult Upsert(CoverType coverType)
 {
     if (ModelState.IsValid)
     {
         var parameter = new DynamicParameters();
         parameter.Add("@Name", coverType.Name);
         if (coverType.Id == 0)
         {
             _unitOfWork.SP_Call.Execute(SD.Proc_CoverType_Create, parameter);
         }
         else
         {
             parameter.Add("@Id", coverType.Id);
             _unitOfWork.SP_Call.Execute(SD.Proc_CoverType_Update, parameter);
         }
         _unitOfWork.Save();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(coverType));
 }
Beispiel #25
0
        public void Execute(ExclusionDeleteDto dto)
        {
            var registro = _context.Exclusiones.SingleOrDefault(x => x.Id == dto.Id);

            if (registro == null)
            {
                throw new EntityNotFoundException("Exclusion", dto.Id.ToString());
            }

            _context.Exclusiones.Remove(registro);
            _context.Save();
        }
Beispiel #26
0
        public void Execute(TipoPerfilDeleteDto dto)
        {
            var registro = _context.TiposPerfil.SingleOrDefault(x => x.Id == dto.Id);

            if (registro == null)
            {
                throw new EntityNotFoundException("TipoPerfiles", dto.Id.ToString());
            }

            _context.TiposPerfil.Remove(registro);
            _context.Save();
        }
Beispiel #27
0
        public void Execute(MotivoBloqueoDeleteDto dto)
        {
            var registro = _context.MotivosBloqueo.SingleOrDefault(x => x.Id == dto.Id);

            if (registro == null)
            {
                throw new EntityNotFoundException("MotivoBloqueos", dto.Id.ToString());
            }

            _context.MotivosBloqueo.Remove(registro);
            _context.Save();
        }
Beispiel #28
0
        public async Task <IActionResult> EnterLobby([FromRoute] Guid id)
        {
            var userId = UInt64.Parse(User.Claims.First().Value.Split("id/")[2]);
            var user   = _unityOfWork.GetRepository <User>().Query(x => x.SteamId == userId)
                         .Include(x => x.Matches).ThenInclude(x => x.GameMatch).FirstOrDefault();
            var gameMatch = _unityOfWork.GetRepository <GameMatch>().Query(x => x.Id == id)
                            .Include(x => x.Matches).ThenInclude(x => x.User).FirstOrDefault();
            var match = gameMatch.Matches.ToList().Find(x => x.UserId == user.Id);

            if (match != null)
            {
                return(Redirect(Url.Action("Match", new { id = gameMatch.Id })));
            }

            match = user.Matches.ToList().Find(x => x.GameMatch.Status != MatchStatus.Finished);
            if (match != null)
            {
                return(Redirect(Url.Action("Match", new { id = match.GameMatchId })));
            }
            _unityOfWork.GetRepository <PlayerToMatch>().Add(
                new PlayerToMatch
            {
                UserId      = user.Id,
                GameMatchId = gameMatch.Id,
                IsLeader    = false
            });
            _unityOfWork.Save();
            await hubContext.Clients.All.SendAsync("UpdateLobby", id);

            return(Redirect(Url.Action("Match", new { id = gameMatch.Id })));
        }
 public ActionResult Create(Manufacturer manufacturer)
 {
     try
     {
         _unityOfWork.Manufacturer.Insert(manufacturer);
         _unityOfWork.Save();
         return(View("~/Views/Ivy/Manufacturer/Index.cshtml"));
     }
     catch
     {
         return(View("~/Views/Ivy/Manufacturer/Index.cshtml"));
     }
 }
Beispiel #30
0
        public void Execute(EstadoFiltroUpdateDto dto)
        {
            var registro = _context.EstadoFiltros.SingleOrDefault(x => x.Id == dto.Id);

            if (registro == null)
            {
                throw new EntityNotFoundException("EstadoFiltro", dto.Id.ToString());
            }

            _mapper.Map(dto, registro);

            _context.Save();
        }