Exemplo n.º 1
0
        public async Task UpsertCredit(Credit credit)
        {
            if (credit.Id <= 0)
            {
                await _unitOfWork.WriteCredits.Create(_mapper.Map(credit));
            }
            else
            {
                await _unitOfWork.WriteCredits.Update(_mapper.Map(credit));
            }

            await _unitOfWork.Save();
        }
Exemplo n.º 2
0
        public void Test2()
        {
            var parentXml = new TcmbXmlParent()
            {
                Tarih      = "10.10.2020",
                Date       = "10.10.2020",
                Currencies = new[]
                {
                    new TcmbXmlChild()
                    {
                        ForexSelling    = "",
                        ForexBuying     = "",
                        BanknoteBuying  = "",
                        BanknoteSelling = "",
                        CrossRateOther  = "",
                        CrossRateUSD    = "",
                    },
                }
            };

            TcmbCurrencyData result = CustomMapper.Map(parentXml).First();

            Assert.Equal(new DateTime(2020, 10, 10), result.Tarih);
            Assert.Equal(new DateTime(2020, 10, 10), result.Date);

            Assert.Null(result.ForexSelling);
            Assert.Null(result.ForexBuying);
            Assert.Null(result.BanknoteBuying);
            Assert.Null(result.BanknoteSelling);
            Assert.Null(result.CrossRateOther);
            Assert.Null(result.CrossRateUsd);
        }
Exemplo n.º 3
0
        public async Task <JsonResult> GetCurrentUserDetails()
        {
            var header = Request.Headers["Authorization"];

            if (header.ToString().StartsWith("Bearer "))
            {
                var  credValue = header.ToString().Substring("Bearer ".Length).Trim();
                long id        = GetAuthentiactedUserId(credValue);
                var  User      = await _userManager.GetAsync(u => u.Id == id);

                if (User == null)
                {
                    return(new JsonResult(new ResponseModel(errors: new List <string> {
                        $"There is no registered user with id {id}"
                    },
                                                            success: false,
                                                            code: HttpStatusCode.BadRequest,
                                                            message: "Authentication failed!"
                                                            )));
                }
                var userDetails = CustomMapper <UserEntity, UserDto> .Map(User);

                return(new JsonResult(new ResponseModel(code: HttpStatusCode.OK, message: "Success", data: new { user = userDetails })));
            }

            return(new JsonResult(new ResponseModel(errors: new List <string> {
                $"Wrong authentication type detected.Use Bearer token"
            },
                                                    success: false,
                                                    code: HttpStatusCode.BadRequest,
                                                    message: "Authentication failed!"
                                                    )));;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get all bank accounts
        /// </summary>
        /// <returns></returns>
        public IEnumerable <BankAccountDTO> GetAll()
        {
            IEnumerable <BankAccount>    bankAccounts    = _db.BankAccounts.GetAll();
            IEnumerable <BankAccountDTO> bankAccountsDTO = CustomMapper <BankAccount, BankAccountDTO> .Map(bankAccounts);

            return(bankAccountsDTO);
        }
Exemplo n.º 5
0
        public async Task <ApartmentDto> Handle(GetApartmentQuery request, CancellationToken cancellationToken)
        {
            var apartment = await context.Apartments.Find(a => a.Id == request.Id)
                            .SingleOrDefaultAsync(cancellationToken);

            return(CustomMapper.Map(apartment));
        }
Exemplo n.º 6
0
        public void BankAccountService_Tests()
        {
            IEnumerable <BankAccount> accs = CustomMapper <BankAccountDTO, BankAccount> .Map(_bankAccounts);

            IRepository <BankAccount> repository = new BankAccountMemoryRepository();

            foreach (var item in accs)
            {
                repository.Create(item);
            }
            IUnitOfWork         unitOfWork = new UnitOfWork(repository);
            IBankAccountService service    = new BankAccountService(unitOfWork);

            BankAccountDTO bankAccount = service.Get(8);

            service.Deposit(bankAccount.Id, 200m);

            Assert.AreEqual(8, bankAccount.Id);
            bankAccount = service.Get(8);
            Assert.AreEqual(700.50m, bankAccount.Balance);
            Assert.AreEqual(20, bankAccount.BonusPoints);

            service.Withdraw(8, 500.50m);
            bankAccount = service.Get(8);
            Assert.AreEqual(200m, bankAccount.Balance);
        }
Exemplo n.º 7
0
        public void Test()
        {
            var parentXml = new TcmbXmlParent()
            {
                Tarih    = "22.11.2020",
                Date     = "22.11.2020",
                BultenNo = "2020/231",

                Currencies = new[]
                {
                    new TcmbXmlChild()
                    {
                        Tarih    = "22.11.2020",
                        Date     = "22.11.2020",
                        BultenNo = "2020/231",

                        CrossOrder   = "1",
                        Kod          = "USD",
                        CurrencyCode = "USD",
                        Unit         = "1",

                        CurrencyNameTurkish = "ABD DOLARI",
                        CurrencyNameEnglish = "US DOLLAR",

                        ForexBuying  = "2.1",
                        ForexSelling = "1.1",

                        BanknoteBuying  = "3.1",
                        BanknoteSelling = "4.1",

                        CrossRateUSD   = "1.99",
                        CrossRateOther = "1.33",
                    },
                }
            };

            TcmbCurrencyData resultTcmbCurrencyData = CustomMapper.Map(parentXml).First();

            Assert.Equal(new DateTime(2020, 11, 22), resultTcmbCurrencyData.Tarih);
            Assert.Equal(new DateTime(2020, 11, 22), resultTcmbCurrencyData.Date);
            Assert.Equal("2020/231", parentXml.BultenNo);

            Assert.Equal(1, resultTcmbCurrencyData.CrossOrder);
            Assert.Equal("USD", resultTcmbCurrencyData.Kod);
            Assert.Equal("USD", resultTcmbCurrencyData.CurrencyCode);
            Assert.Equal("1", resultTcmbCurrencyData.Unit);

            Assert.Equal("ABD DOLARI", resultTcmbCurrencyData.CurrencyNameTurkish);
            Assert.Equal("US DOLLAR", resultTcmbCurrencyData.CurrencyNameEnglish);

            Assert.Equal(2.1M, resultTcmbCurrencyData.ForexBuying);
            Assert.Equal(1.1M, resultTcmbCurrencyData.ForexSelling);

            Assert.Equal(3.1M, resultTcmbCurrencyData.BanknoteBuying);
            Assert.Equal(4.1M, resultTcmbCurrencyData.BanknoteSelling);

            Assert.Equal(1.99M, resultTcmbCurrencyData.CrossRateUsd);
            Assert.Equal(1.33M, resultTcmbCurrencyData.CrossRateOther);
        }
        public async Task <QueueItem> MapQueueItem(WorkQueueViewModel model, string userName)
        {
            model.QueueItemViewModel = await GetQuestionSet(_queueItemGroupId);

            var csuCallbackItem = _customMapper.Map(model.DomainViewModel.DomainInfoViewModels, model.DomainViewModel.DomainGroup.ClassMapping);
            var queueItem       = (QueueItem)_customMapper.Map(model.QueueItemViewModel.DomainInfoViewModels, model.QueueItemViewModel.DomainGroup.ClassMapping);

            queueItem = (QueueItem)_customMapper.MapProperty(queueItem, "CreatedDate", DateTime.Now);
            queueItem = (QueueItem)_customMapper.MapProperty(queueItem, "CreatedBy", userName);
            queueItem = (QueueItem)_customMapper.MapProperty(queueItem, "QueueID", int.Parse(model.DomainViewModel.DomainGroup.ExternalReferenceId));
            queueItem = (QueueItem)_customMapper.MapProperty(queueItem, "QueueGroupID", int.Parse(model.QueueItemViewModel.DomainGroup.ExternalReferenceId));
            queueItem = (QueueItem)_customMapper.MapProperty(queueItem, "CustomerName", _customMapper.GetProperty(csuCallbackItem, "NameOfcaller"));
            queueItem = (QueueItem)_customMapper.MapProperty(queueItem, "WescotRef", _customMapper.GetProperty(csuCallbackItem, "WescotRef"));
            queueItem = (QueueItem)_customMapper.MapProperty(queueItem, "Summary", _customMapper.GetProperty(csuCallbackItem, "ReasonForCallback"));
            queueItem = (QueueItem)_customMapper.MapProperty(queueItem, "DueDate", _customMapper.GetProperty(csuCallbackItem, "DateForCallback"));

            return(queueItem);
        }
Exemplo n.º 9
0
        public AddressDto(Address address)
        {
            if (address is null)
            {
                return;
            }

            CustomMapper.Map(address, this);
        }
Exemplo n.º 10
0
        public ActionResult Withdraw(int id)
        {
            BankAccountViewModel bankAccount = CustomMapper<BankAccountDTO, BankAccountViewModel>.Map(_service.Get(id));
            if (bankAccount?.IsOpened == true)
            {
                return PartialView("WithdrawPartial", bankAccount);
            }

            return HttpNotFound();
        }
Exemplo n.º 11
0
        public UserDto(IUser user, long?id = null)
        {
            if (user is null)
            {
                return;
            }

            this.Id = id;
            CustomMapper.Map(user, this);
        }
Exemplo n.º 12
0
        public async Task <IEnumerable <ReservationDto> > Handle(GetAllReservationsQuery request, CancellationToken cancellationToken)
        {
            IMongoQueryable <ReservationModel> query = this.context.Reservations.AsQueryable();

            query = this.ApplyFilters(request, query);

            var reservations = await query.ToListAsync(cancellationToken).ConfigureAwait(false);

            return(reservations.Select(r => CustomMapper.Map <ReservationDto>(r)));
        }
Exemplo n.º 13
0
        public UserDto(IUserRole userRole)
        {
            if (userRole is null || userRole.User is null)
            {
                return;
            }

            this.Id = userRole.User.Id;
            CustomMapper.Map(userRole.User, this);
        }
        public async Task <IEnumerable <UserDto> > Handle(GetAllUsersQuery request, CancellationToken cancellationToken)
        {
            IMongoQueryable <UserModel> query = this.context.Users.AsQueryable();

            query = ApplyFilters(request, query);

            var users = await query.ToListAsync(cancellationToken).ConfigureAwait(false);

            return(users.Select(u => CustomMapper.Map <UserDto>(u)));
        }
Exemplo n.º 15
0
        public async Task <UserDto> Handle(GetUserByIdQuery request, CancellationToken cancellationToken)
        {
            var dbUser = await context.Users.Find(u => u.Id == request.Id).SingleOrDefaultAsync(cancellationToken);

            if (dbUser is null)
            {
                throw new NotFoundException($"User with id={request.Id} could not be found!");
            }

            return(CustomMapper.Map <UserDto>(dbUser));
        }
Exemplo n.º 16
0
        /// <summary>
        /// Create new bank account
        /// </summary>
        /// <param name="bankAccountDTO"></param>
        public void CreateNew(BankAccountDTO bankAccountDTO)
        {
            if (bankAccountDTO == null)
            {
                throw new ArgumentNullException("Bank account can't be null!!");
            }

            BankAccount bankAccount = CustomMapper <BankAccountDTO, BankAccount> .Map(bankAccountDTO); ////new BankAccount

            _db.BankAccounts.Create(bankAccount);
        }
Exemplo n.º 17
0
        public async Task <List <TcmbCurrencyData> > GetCurrencyData()
        {
            HttpResponseMessage httpResponse = await _odeonDownloader.DownloadCurrencyDataAsync();

            XmlSerializer xmlSerializer = new XmlSerializer(typeof(TcmbXmlParent));
            Stream        stream        = await httpResponse.Content.ReadAsStreamAsync();

            TcmbXmlParent           tcmbXmlParent = (TcmbXmlParent)xmlSerializer.Deserialize(stream);
            List <TcmbCurrencyData> currencies    = CustomMapper.Map(tcmbXmlParent);

            return(currencies);
        }
Exemplo n.º 18
0
        public async Task <JsonResult> Get(string username)
        {
            var userEntity = await _userManager.GetAsync(u => u.Username == username);

            if (userEntity == null)
            {
                return(new JsonResult(new ResponseModel(message: $"There is no user with username {username}", code: HttpStatusCode.BadRequest, success: false)));
            }
            var user = CustomMapper <UserEntity, LimitedUserDto> .Map(userEntity);

            return(new JsonResult(new ResponseModel(code: HttpStatusCode.OK, message: "Success", data: user)));
        }
Exemplo n.º 19
0
        public async Task <IEnumerable <ApartmentDto> > Handle(GetAllApartmentsQuery request, CancellationToken cancellationToken)
        {
            var query = this.context.Apartments.AsQueryable();

            query = ApplyBasicFilters(request, query);

            var apartments = await query.ToListAsync(cancellationToken).ConfigureAwait(false);

            var filtered = this.ApplyComplexFilters(request, apartments);

            return(filtered.Select(a => CustomMapper.Map(a)).ToList());
        }
Exemplo n.º 20
0
        private List <Films> MapData(string json)
        {
            JObject      json2 = JObject.Parse(json);
            var          j     = json2["results"];
            List <Films> films = new List <Films>();

            foreach (var item in j)
            {
                films.Add(_customMapper.Map(JObject.Parse(item.ToString())));
            }
            return(films);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Get bank account by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public BankAccountDTO Get(int id)
        {
            BankAccount bankAccount = _db.BankAccounts.GetById(id);

            if (bankAccount == null)
            {
                throw new ArgumentNullException("Bank account doesn't exist!!");
            }

            BankAccountDTO bankAccountDTO = CustomMapper <BankAccount, BankAccountDTO> .Map(bankAccount); ////new BankAccountDTO

            return(bankAccountDTO);
        }
Exemplo n.º 22
0
        public ActionResult Open(int id)
        {
            BankAccountViewModel bankAccount = CustomMapper<BankAccountDTO, BankAccountViewModel>.Map(_service.Get(id));
            if (_service.Get(id) != null)
            {
                _service.Open(id);
                bankAccount.IsOpened = true;

                return PartialView("OpenClosePartial", bankAccount);
            }

            return HttpNotFound("Can't open bank account");
        }
        public async Task <UserDto> Handle(GetUserByUsernameQuery request, CancellationToken cancellationToken)
        {
            var dbUser = await this.context.Users
                         .Find(u => u.Username == request.Username)
                         .ToListAsync(cancellationToken)
                         .ConfigureAwait(false);

            if (dbUser is null)
            {
                throw new NotFoundException($"Could not find user with username '{request.Username}'");
            }

            return(CustomMapper.Map <UserDto>(dbUser));
        }
Exemplo n.º 24
0
        public async Task <JsonResult> Get(long id)
        {
            var entity = await _fileManager.GetAsync(id);

            if (entity == null)
            {
                return(new JsonResult(new ResponseModel(success: false)));
            }
            var file = CustomMapper <FileEntity, FileDto> .Map(entity);

            file.Size     = new FileInfo(Path.Combine(_env.WebRootPath, file.Path)).Length / Math.Pow(1024, 2);
            file.Duration = Dir.GetVideoDuration(Path.Combine(_env.WebRootPath, file.Path));
            return(new JsonResult(new ResponseModel(data: file)));
        }
Exemplo n.º 25
0
        public int UpdatePet(Pet_x pet)//-----------------------------------------------
        {
            int result = -1;
            using (var context = new PetSitterDbContext())
            {
                var freshPet = MapToDamain(pet);
                var curPet = context.Pets.Where(x => x.Id == pet.Id).FirstOrDefault();
                CustomMapper.Map<Pet, Pet>(freshPet, curPet);
                context.SaveChanges();
                result = 0;
            }

            return result;
        }
Exemplo n.º 26
0
        public async Task <bool> PostCSU(WorkQueueViewModel model, string userName)
        {
            model.QueueItemViewModel = await GetQuestionSet(_queueItemGroupId);

            bool result = false;

            try
            {
                var csuCallbackItem = _customMapper.Map(model.DomainViewModel.DomainInfoViewModels, model.DomainViewModel.DomainGroup.ClassMapping);
                var queueItem       = _customMapper.Map(model.QueueItemViewModel.DomainInfoViewModels, model.QueueItemViewModel.DomainGroup.ClassMapping);

                queueItem = _customMapper.MapProperty(queueItem, "CreatedDate", DateTime.Now);
                queueItem = _customMapper.MapProperty(queueItem, "CreatedBy", userName);
                queueItem = _customMapper.MapProperty(queueItem, "QueueID", int.Parse(model.DomainViewModel.DomainGroup.ExternalReferenceId));
                queueItem = _customMapper.MapProperty(queueItem, "QueueGroupID", int.Parse(model.QueueItemViewModel.DomainGroup.ExternalReferenceId));
                queueItem = _customMapper.MapProperty(queueItem, "CustomerName", _customMapper.GetProperty(csuCallbackItem, "NameOfcaller"));
                queueItem = _customMapper.MapProperty(queueItem, "WescotRef", _customMapper.GetProperty(csuCallbackItem, "WescotRef"));
                queueItem = _customMapper.MapProperty(queueItem, "Summary", _customMapper.GetProperty(csuCallbackItem, "ReasonForCallback"));
                queueItem = _customMapper.MapProperty(queueItem, "DueDate", _customMapper.GetProperty(csuCallbackItem, "DateForCallback"));

                csuCallbackItem = _customMapper.MapProperty(csuCallbackItem, "ReasonForTransfer", "NULL");

                QItemHolder qItemHolder = new QItemHolder
                {
                    queueItem = (QueueItem)queueItem,
                    TModel    = csuCallbackItem
                };

                result = await _httpClientConnectionQItemHolder.PostAsync(qItemHolder);
            }
            catch (Exception ex)
            {
                var x = ex.Message;
            }

            return(result);
        }
        public When_converting_to_object_with_abstract_properties_in_absence_of_type_information()
        {
            dynamicObject = new DynamicObject()
            {
                { "Ref", new DynamicObject() },
                { "Value1", "the value's pay load" },
                { "Value2", 222 },
                { "Value3", null },
                { "Value4", new DynamicObject() },
            };

            var mapper = new CustomMapper();

            obj = mapper.Map<ClassWithAbstractProperties>(dynamicObject);
        }
Exemplo n.º 28
0
        public ActionResult Create(BankAccountViewModel bankAccount)
        {
            if (ModelState.IsValid)
            {
                if (bankAccount != null)
                {
                    var bankAccountDTO = CustomMapper<BankAccountViewModel, BankAccountDTO>.Map(bankAccount);
                    _service.CreateNew(bankAccountDTO);

                    return RedirectToAction("Index");
                }
            }

            return HttpNotFound("Can't create bank account");
        }
Exemplo n.º 29
0
        public int UpdateUser(User_x user)
        {
            int result = -1;
            using (var context = new PetSitterDbContext())
            {
                var updatingUser = context.Users.Where(x => x.Id == user.Id).FirstOrDefault();
                if (updatingUser != null)
                {
                    CustomMapper.Map<User_x, User>(user, updatingUser);
                    context.SaveChanges();
                    result = 0;
                }
            }

            return result;
        }
Exemplo n.º 30
0
        public ActionResult Index(int page = 1)
        {
            IEnumerable<BankAccountViewModel> bankAccounts = CustomMapper<BankAccountDTO, BankAccountViewModel>.Map(_service.GetAll());

            PageViewModel<BankAccountViewModel> pvm = new PageViewModel<BankAccountViewModel>
            {
                Items = bankAccounts.OrderBy(b => b.Id).Skip((page - 1) * PAGE_SIZE).Take(PAGE_SIZE),
                PagingInfo = new PagingInfo
                {
                    CurrentPage = page,
                    ItemsPerPage = PAGE_SIZE,
                    TotalItems = bankAccounts.Count()
                }
            };

            return View(pvm);
        }
        public When_converting_to_object_with_abstract_properties_in_absence_of_type_information()
        {
            dynamicObject = new DynamicObject()
            {
                Properties = new PropertySet
                {
                    { "Ref", new DynamicObject() },
                    { "Value1", "the value's pay load" },
                    { "Value2", 222 },
                    { "Value3", null },
                    { "Value4", new DynamicObject() },
                },
            };

            var mapper = new CustomMapper();

            obj = mapper.Map <ClassWithAbstractProperties>(dynamicObject);
        }