Beispiel #1
0
        public Comprobante Create(Comprobante comprobante)
        {
            Numerador numerador;

            if (comprobante.fecha_comprobante < DateTime.Today)
            {
                throw new Exception(ConstantesTexto.ErrorFechaMenAct);
            }
            try
            {
                numerador =
                    _unitOfWork.NumeradorRepository
                    .Get(filter: x => x.id_tipo_comprobante == comprobante.id_tipo_comprobante &&
                         x.letra == comprobante.letra_comprobante &&
                         x.sucursal == comprobante.suc_comprobante)
                    .SingleOrDefault()
                    ?? _unitOfWork.NumeradorRepository.Create
                    (
                        new Numerador()
                {
                    id_tipo_comprobante = comprobante.id_tipo_comprobante,
                    letra    = comprobante.letra_comprobante,
                    sucursal = comprobante.suc_comprobante,
                    numero   = 0
                }
                    );

                numerador.numero           += 1;
                comprobante.num_comprobante = numerador.numero;

                ValidateModel <Comprobante> .Default.Validar(comprobante);

                ValidateModel <ComprobanteDetalle> .Default.Validar(comprobante.ComprobanteDetalle.ToList());

                _unitOfWork.SaveChanges();

                if (comprobante.id_tipo_comprobante.Equals(TipoComprobante.SIR.ToString()))
                {
                    comprobante.Etiquetas = GetEtiquetas(comprobante);
                }

                comprobante = _unitOfWork.ComprobanteRepository.Create(comprobante);
                _unitOfWork.NumeradorRepository.Update(numerador);
                _unitOfWork.SaveChanges();

                BitacoraModel.Default.RegistrarEnBitacora
                (
                    Evento.ComprobanteGenerado,
                    Severidad.Informativo,
                    comprobante.Descripcion
                );

                return(comprobante);
            }
            catch (Exception ex)
            {
                Log.Save(this, ex);
                throw ex;
            }
        }
Beispiel #2
0
            public async Task <bool> Handle(UpdateBankInfoCommand request, CancellationToken cancellationToken)
            {
                var bankFromRepo = await _bankRepository.RetrieveById(request.BankId);

                if (bankFromRepo == null)
                {
                    throw new NotFoundException(nameof(Bank), request.BankId);
                }

                _mapper.Map(request.BankForUpdateDto, bankFromRepo);
                return(await _unitOfWorkRepository.SaveChanges() > 0);
            }
Beispiel #3
0
            public async Task <bool> Handle(UpdateCategoryCommand request, CancellationToken cancellationToken)
            {
                var categoryFromRepo = await _categoryRepository.RetrieveById(request.CategoryId);

                if (categoryFromRepo == null)
                {
                    throw new NotFoundException(nameof(Category), request.CategoryId);
                }

                _mapper.Map(request.CategoryForUpdateDto, categoryFromRepo);
                return(await _unitOfWorkRepository.SaveChanges() > 0);
            }
            public async Task <bool> Handle(UpdateExpenseCommand request, CancellationToken cancellationToken)
            {
                var expenseFromRepo = await _expenseRepository.RetrieveById(request.ExpenseId);

                if (expenseFromRepo == null)
                {
                    throw new NotFoundException(nameof(Expense), request.ExpenseId);
                }

                _mapper.Map(request.ExpenseForUpdateDto, expenseFromRepo);
                return(await _unitOfWorkRepository.SaveChanges() > 0);
            }
            public async Task <bool> Handle(UpdateAccountCommand request, CancellationToken cancellationToken)
            {
                var accountFromRepo = await _accountRepository.RetrieveById(request.AccountId);

                if (accountFromRepo == null)
                {
                    throw new NotFoundException(nameof(Account), request.AccountId);
                }

                _mapper.Map(request.AccountForUpdateDto, accountFromRepo);
                return(await _unitOfWorkRepository.SaveChanges() > 0);
            }
            public async Task <bool> Handle(DeleteAccountCommand request, CancellationToken cancellationToken)
            {
                var accountFromRepo = await _accountRepository.RetrieveById(request.AccountId);

                if (accountFromRepo == null)
                {
                    throw new NotFoundException(nameof(Account), request.AccountId);
                }

                // Soft delete
                accountFromRepo.IsDeleted = true;
                return(await _unitOfWorkRepository.SaveChanges() > 0);
            }
Beispiel #7
0
            public async Task <bool> Handle(DeleteBankInfoCommand request, CancellationToken cancellationToken)
            {
                var bankFromRepo = await _bankRepository.RetrieveById(request.BankId);

                if (bankFromRepo == null)
                {
                    throw new NotFoundException(nameof(Bank), request.BankId);
                }

                // Soft delete
                bankFromRepo.IsDeleted = true;
                return(await _unitOfWorkRepository.SaveChanges() > 0);
            }
Beispiel #8
0
            public async Task <CategoryToReturnDto> Handle(CreateCategoryCommand request, CancellationToken cancellationToken)
            {
                var category = _mapper.Map <Category>(request.CategoryForCreationDto);
                await _categoryRepository.Add(category);

                if (await _unitOfWorkRepository.SaveChanges() > 0)
                {
                    var categoryToReturn = _mapper.Map <CategoryToReturnDto>(category);
                    categoryToReturn.CanBeDeleted = true;
                    return(categoryToReturn);
                }

                return(null);
            }
Beispiel #9
0
            public async Task <int> Handle(CreateUserLoginHistoryCommand request, CancellationToken cancellationToken)
            {
                var location = _userResolverService.GetUsersLocation().Result;

                var userLoginHistory = _mapper.Map <UserLoginHistory>(request.UserLoginHistoryForCreationDto);

                userLoginHistory.ActionDateTime = DateTimeOffset.UtcNow;
                userLoginHistory.GeoLocation    = location.ToString();
                userLoginHistory.IPAddress      = location.Ip;

                await _unitOfWorkRepository.Context.UserLoginHistories.AddAsync(userLoginHistory);

                return(await _unitOfWorkRepository.SaveChanges());
            }
Beispiel #10
0
            public async Task <ExpenseToReturnDto> Handle(CreateExpenseCommand request, CancellationToken cancellationToken)
            {
                var expense = _mapper.Map <Expense>(request.ExpenseForCreationDto);
                await _expenseRepository.Add(expense);

                if (await _unitOfWorkRepository.SaveChanges() > 0)
                {
                    expense.Category = await _unitOfWorkRepository.Context.Categories.FindAsync(expense.CategoryId);

                    expense.Currency = await _unitOfWorkRepository.Context.Currencies.FindAsync(expense.CurrencyId);

                    return(_mapper.Map <ExpenseToReturnDto>(expense));
                }

                return(null);
            }
            public async Task <bool> Handle(DeleteCategoryCommand request, CancellationToken cancellationToken)
            {
                if (await _categoryRepository.ExistsAnyExpensesConnectedToCategory(request.CategoryId))
                {
                    return(false);
                }

                var categoryFromRepo = await _categoryRepository.RetrieveById(request.CategoryId);

                if (categoryFromRepo == null)
                {
                    throw new NotFoundException(nameof(Category), request.CategoryId);
                }

                _categoryRepository.Delete(categoryFromRepo);
                return(await _unitOfWorkRepository.SaveChanges() > 0);
            }
            public async Task <UserForDetailDto> Handle(UpdateUserSettingsCommand request, CancellationToken cancellationToken)
            {
                var userFromRepo = await _userUepository.RetrieveById(request.UserId);

                if (userFromRepo == null)
                {
                    throw new NotFoundException(nameof(User), request.UserId);
                }

                _mapper.Map(request.UserForUpdateDto, userFromRepo);
                if (await _unitOfWorkRepository.SaveChanges() > 0)
                {
                    return(_mapper.Map <UserForDetailDto>(userFromRepo));
                }

                return(null);
            }
 public void RegistrarEnBitacora(Bitacora entradaEnBitacora)
 {
     _unitOfWork.BitacoraRepository.RegistrarEnBitacora(entradaEnBitacora);
     _unitOfWork.SaveChanges();
 }
Beispiel #14
0
        public IActionResult CheckOut(CheckOutAndCartModel model)
        {
            // try catch blguna al burayı  UNUTMA

            var cart = HttpContext.Session.GetJson <Cart>("Cart")?.Products ?? null;

            //    Dictionary<string, dynamic> responseData = new Dictionary<string, dynamic>();
            //    string data = "entityId=8a8294174b7ecb28014b9699220015ca" +
            //"&amount=92.00" +
            //"&currency=EUR" +
            //"&paymentType=DB";

            //bool res = GetCartResult(responseData, data);


            List <CartLine>      cartline             = new List <CartLine>();
            CheckOutAndCartModel checkoutInformations = new CheckOutAndCartModel();
            Random random = new Random();
            int    guid   = random.Next(100, 9999);


            //CheckoutModel Gereksiz sil
            var UserCartSaveInformation = new CheckOutLine();
            var userGeneralInformation  = new CheckOut();

            foreach (var item in cart)
            {
                cartline.Add(new CartLine
                {
                    CartLineId    = guid,
                    Product       = item.Product,
                    Quantity      = item.Quantity,
                    ShippingPrice = item.ShippingPrice
                });
                checkoutInformations.CartLines = cartline;
            }
            foreach (var item2 in checkoutInformations.CartLines)
            {
                UserCartSaveInformation.UserId         = User.FindFirstValue(ClaimTypes.NameIdentifier);
                UserCartSaveInformation.CheckOutNumber = guid;
                UserCartSaveInformation.ProductCodes  += item2.Product.ProductsId + " ) " + item2.Product.ProductName + " , ";
                UserCartSaveInformation.CheckOutDate   = DateTime.Now;
                UserCartSaveInformation.Quantity       = item2.Quantity;
                UserCartSaveInformation.Total          = 55;
            }
            uow.CheckOutLine.Add(UserCartSaveInformation);
            uow.SaveChanges();


            userGeneralInformation.UserId           = User.FindFirstValue(ClaimTypes.NameIdentifier);
            userGeneralInformation.CheckOutLineId   = guid;
            userGeneralInformation.FirstName        = model.CheckOutmodel.FirstName;
            userGeneralInformation.LastName         = model.CheckOutmodel.LastName;
            userGeneralInformation.Email            = model.CheckOutmodel.Email;
            userGeneralInformation.Telephone        = model.CheckOutmodel.Telephone;
            userGeneralInformation.Address1         = model.CheckOutmodel.Address1;
            userGeneralInformation.Address2         = model.CheckOutmodel.Address2;
            userGeneralInformation.City             = model.CheckOutmodel.City;
            userGeneralInformation.PostCode         = model.CheckOutmodel.PostCode;
            userGeneralInformation.PaymentMethod    = model.CheckOutmodel.PaymentMethod;
            userGeneralInformation.Total            = model.CheckOutmodel.Total;
            userGeneralInformation.IsApprovePayment = model.CheckOutmodel.IsApprovePayment; // <= odeme onaylanırsa True yada false donecek servisden gelen degere gore
            userGeneralInformation.Result           = "Hede";                               // servisten donen strin basılcak
            uow.CheckOut.Add(userGeneralInformation);
            uow.SaveChanges();

            return(View());
        }
Beispiel #15
0
 public IActionResult AddCategory(Categories model)
 {
     if (ModelState.IsValid)
     {
         uow.Category.Add(model);
         uow.SaveChanges();
         TempData["message"] = $"{model.CategoriesName} is Save to Categories";
         return(RedirectToAction("GetCategoryList", "Admin"));
     }
     return(View(model));
 }