示例#1
0
        private async Task AddNewCarRecord()
        {
            var fuelType = await _service.GetAllAsync <FuelType>();

            var transmissionTypes = await _service.GetAllAsync <Transmission>();

            Console.Write("Model: ");
            var model = Console.ReadLine();

            Console.Write("Engine Details: ");
            var engine = Console.ReadLine();

            Console.Write("Color: ");
            var color = Console.ReadLine();

            Console.Write("Price/Day ($): ");
            var priceDay = int.Parse(Console.ReadLine());

            Console.Write("Back type: ");
            var back = Console.ReadLine();

            Console.WriteLine("Fuel: ");
            foreach (var fuel in fuelType)
            {
                Console.WriteLine($"Id - {fuel.Id} | Title: {fuel.Title}");
            }
            Console.Write("Enter fuelId: ");
            var fuelId = long.Parse(Console.ReadLine());

            Console.WriteLine("Transmission: ");
            foreach (var tr in transmissionTypes)
            {
                Console.WriteLine($"Id - {tr.Id} | Title: {tr.Title}");
            }
            Console.Write("Enter fuelId: ");
            var transmissionId = long.Parse(Console.ReadLine());


            var car = new Car
            {
                ModelName = model, EngineDetails = engine, PricePerDay = priceDay,
                Back      = back, FuelTypeId = fuelId, Color = color, TransmissionId = transmissionId
            };

            try
            {
                await _service.AddAsync <Car>(car);

                Thread.Sleep(2000);
                Console.WriteLine("Car successfully added to database.");
                Thread.Sleep(1000);
            }
            catch (Exception)
            {
                Console.WriteLine("Some error happened.");
            }
        }
示例#2
0
        public async Task <TEntity> AddAsync <TEntity>(TEntity entity) where TEntity : class
        {
            var logMsg = new StringBuilder();

            logMsg
            .AppendLine(DateTime.UtcNow.ToString())
            .AppendLine($"Add new {typeof(TEntity).ToString().Split('.').Last()}.")
            .Append(Delimeter);
            await LogToFile(logMsg.ToString());

            return(await _repository.AddAsync <TEntity>(entity));
        }
        public async Task <IActionResult> Add([FromBody] TodoItem newItem)
        {
            if (newItem != null)
            {
                await todoRepositoryService.AddAsync(newItem);

                return(CreatedAtRoute("GetTodo", new { id = newItem.Id }, newItem));
            }
            else
            {
                return(BadRequest());
            }
        }
示例#4
0
        public async Task <IActionResult> PostUserAsync([FromBody] UserModel user)
        {
            try
            {
                if (!ModelState.IsValid || user == null)
                {
                    return(BadRequest());
                }

                await _repositoryService.AddAsync(user);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok());
        }
示例#5
0
        public async Task <IActionResult> PostPinAsync([FromBody] PinModel pin)
        {
            try
            {
                if (!ModelState.IsValid || pin == null)
                {
                    return(BadRequest());
                }

                await _repositoryService.AddAsync(pin);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok());
        }
        public async void GotoBackSaved()
        {
            currentPerson.Name        = TempPerson.Name;
            currentPerson.LastName    = TempPerson.LastName;
            currentPerson.Notes       = TempPerson.Notes;
            currentPerson.Email       = TempPerson.Email;
            currentPerson.PathToImage = TempPerson.PathToImage;

            if (currentState == States.Add)
            {
                await PersonsRepositary.AddAsync(currentPerson);
            }
            if (currentState == States.Edit)
            {
                await PersonsRepositary.UpdateAsync(currentPerson);
            }
            await NavigationService.NavigateAsync(typeof(Views.MasterDetailPage));
        }
示例#7
0
 public async Task AddCardAsync(CardDetails card)
 {
     await _contextService.AddAsync(card).ConfigureAwait(false);
 }
示例#8
0
 public async Task <Transaction> CreateTransactionAsync(Transaction entity)
 {
     return(await _contextService
            .AddAsync(entity)
            .ConfigureAwait(false));
 }