Пример #1
0
        public async Task <IActionResult> PutVehicletype(int id, Vehicletype vehicletype)
        {
            if (id != vehicletype.Id)
            {
                return(BadRequest());
            }

            _context.Entry(vehicletype).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VehicletypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> PutAddress(int id, Address address)
        {
            if (id != address.Id)
            {
                return(BadRequest());
            }

            _context.Entry(address).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AddressExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #3
0
        public async Task <IActionResult> PackOff(int id)
        {
            try
            {
                var seguimiento = await _context.Pedidos.FindAsync(id);

                if (seguimiento == null)
                {
                    return(NotFound());
                }

                seguimiento.Despachador        = User.Identity.Name;
                seguimiento.PedFase            = 'I';
                seguimiento.PedFechaDespachado = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.Local);

                _flashMessage.Confirmation($"Pedido con Factura Nro {seguimiento.InvoiceNumber} despachado.");

                await _context.SaveChangesAsync();
            }
            catch
            {
                _flashMessage.Danger($"Error al despachar el pedido.");
            }
            return(RedirectToAction(nameof(Index)));
        }
Пример #4
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Location).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LocationExists(Location.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Пример #5
0
        public async Task <bool> AddAnArmyAsync(Army request)
        {
            _logger.LogInformation($"Attempting to add an army with name: {request.Name} to the database...");
            var battle = await _battleRepository.GetInitializingBattleAsync();

            request.BattleId = battle?.Id ?? 0;

            if (battle is null)
            {
                request.BattleId = await _battleRepository.CreateBattleAsync();
            }

            if (battle?.Armies?.Count(x => x.BattleId == request.BattleId && x.Name == request.Name) > 0)
            {
                throw new Exception($"An army with the name {request.Name} already exist for the current battle. Please choose another army name.");
            }

            await _trackingContext.AddAsync(request);

            var result = await _trackingContext.SaveChangesAsync();

            if (result > 0)
            {
                _logger.LogInformation($"Adding an army with name: {request.Name} successful...");
                return(true);
            }
            else
            {
                _logger.LogError($"Adding an army with name: {request.Name} failed!");
                return(false);
            }
        }
Пример #6
0
 public async Task Create(Shipment ship, TrackingContext context)
 {
     ship.ID       = Guid.NewGuid().ToString();
     ship.IsClosed = !Contants.CLOSED;
     ship          = setUpper(ship);
     context.Shipment.Add(ship);
     await context.SaveChangesAsync();
 }
Пример #7
0
 public async Task Create(User user, TrackingContext context)
 {
     user.Password = EncryptionUtil.Encrypt(user.Password, true);
     user.Active   = true;
     user.ID       = Guid.NewGuid().ToString();
     context.User.Add(user);
     await context.SaveChangesAsync();
 }
 public async Task Create(ContactActivity contact, TrackingContext context)
 {
     contact.ID          = Guid.NewGuid().ToString();
     contact.IsRead      = false;
     contact.CreatedDate = DateTime.Now;
     context.ContactActivity.Add(contact);
     await context.SaveChangesAsync();
 }
        public async Task UpdateInfoOfItemAsync(Item itemUpdated)
        {
            using var _trackingContext = new TrackingContext(_options);
            var item = await _trackingContext.Items.Where(i => i.ItemId == itemUpdated.ItemId).FirstOrDefaultAsync() ??
                       throw new Exception($"{Exceptions.ITEM_NOT_FOUND_EXCEPTION}");

            _updateInfoHelper.GetUpdatedItem(ref item, itemUpdated);
            await _trackingContext.SaveChangesAsync();
        }
Пример #10
0
        public async Task SetWaitingForAddAsync(int userId, bool newValue)
        {
            using var _trackingContext = new TrackingContext(_options);
            var userStatus = await _trackingContext.UserStatuses.Where(x => x.UserId == userId).FirstOrDefaultAsync() ??
                             throw new Exception($"{Exceptions.USER_NOT_FOUND_EXCEPTION}");

            userStatus.waitingForAdd = newValue;
            await _trackingContext.SaveChangesAsync();
        }
Пример #11
0
        public async Task <bool> AddUserStatusAsync(int userId)
        {
            using var _trackingContext = new TrackingContext(_options);
            await _trackingContext.UserStatuses.AddAsync(new UserStatus { UserId = userId, waitingForAdd = false });

            await _trackingContext.SaveChangesAsync();

            return(false);
        }
        public async Task <Unit> Handle(SaveTaskListRequest request, CancellationToken cancellationToken)
        {
            var entity = _mapper.Map <Domain.Entities.TaskList>(request.TaskList);
            await _context.TaskLists.AddAsync(entity, cancellationToken);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Пример #13
0
        public async Task <int> AddNewItemAsync(Item item)
        {
            using var _trackingContext = new TrackingContext(_options);
            await _trackingContext.Items.AddAsync(item);

            await _trackingContext.SaveChangesAsync();

            var result = await _trackingContext.Items.Where(x => x.Url.Equals(item.Url)).FirstOrDefaultAsync();

            return(result.ItemId);
        }
Пример #14
0
        public async Task InsertBattleLogAsync(IEnumerable <BattleLog> battleLogs)
        {
            await _trackingContext.BattleLogs.AddRangeAsync(battleLogs);

            var result = await _trackingContext.SaveChangesAsync();

            if (result > 0)
            {
                _logger.LogInformation($"BattleLogs saved in batch!");
            }
        }
Пример #15
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Students.Add(Student);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Пример #16
0
        public async Task <Unit> Handle(UpdateTaskListRequest request, CancellationToken cancellationToken)
        {
            var entity = _mapper.Map <Domain.Entities.TaskList>(request.TaskList);

            if (!_context.TaskLists.Local.Any(x => x.Id == request.Id))
            {
                _context.Update(entity);
            }

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
        public async Task <Unit> Handle(DeleteTaskRequest request, CancellationToken cancellationToken)
        {
            var entity = await _context.Tasks.FindAsync(request.Id);

            if (entity == null)
            {
                throw new System.Exception();
            }
            _context.Tasks.Remove(entity);
            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Пример #18
0
        public async Task <int> CreateBattleAsync()
        {
            var battle = new Battle
            {
                BattleStatus = BattleStatus.Initializing,
            };

            await _trackingContext.Battles.AddAsync(battle);

            var result = await _trackingContext.SaveChangesAsync();

            if (result > 0)
            {
                _logger.LogInformation($"Created new battle with status: {BattleStatus.Initializing} and id: {battle.Id}");
            }
            else
            {
                _logger.LogError($"Failed to create new battle with status: {BattleStatus.Initializing}");
            }

            return(battle.Id);
        }
Пример #19
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            EventLog.TimeStamp = DateTime.Now;
            _context.EventLogs.Add(EventLog);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Пример #20
0
        public async Task RemoveItemAsync(string url)
        {
            using var _trackingContext = new TrackingContext(_options);
            var itemToRemove = await _trackingContext.Items.Where(x => x.Name.Equals(url)).FirstOrDefaultAsync() ??
                               throw new Exception($"{Exceptions.REMOVE_EXCEPTION} {Exceptions.NOT_FOUND_IN_DB_EXCEPTION}");

            try
            {
                _trackingContext.Items.Remove(itemToRemove);
            } catch (Exception ex)
            {
                throw new Exception($"{Exceptions.REMOVE_EXCEPTION} {Exceptions.REMOVE_FROM_DB_EXCEPTION} {ex.Message}");
            }
            await _trackingContext.SaveChangesAsync();
        }
        public async Task <Unit> Handle(SaveMainAccountGroupRequest request, CancellationToken cancellationToken)
        {
            var entity = _mapper.Map <Domain.Entities.MainAccountGroup>(request.MainAccountGroup);

            if (!_context.Ledgers.Any(x => x.Id == request.LedgerId))
            {
                throw new NotFoundException("Ledger", request.LedgerId);
            }

            entity.LedgerId = request.LedgerId;
            await _context.MainAccountGroups.AddAsync(entity, cancellationToken);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Пример #22
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            EventLog = await _context.EventLogs.FindAsync(id);

            if (EventLog != null)
            {
                _context.EventLogs.Remove(EventLog);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Пример #23
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Location = await _context.Locations.FindAsync(id);

            if (Location != null)
            {
                _context.Locations.Remove(Location);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Пример #24
0
        public async Task <Unit> Handle(SaveTransactionRequest request, CancellationToken cancellationToken)
        {
            var entity = _mapper.Map <Domain.Entities.Transaction>(request.Transaction);

            if (!_context.Ledgers.Any(x => x.Id == request.LedgerId))
            {
                throw new NotFoundException("Ledger", request.LedgerId);
            }

            var lastIdentifyingCodeUsed = await _context.Transactions
                                          .Where(x => x.LedgerId == request.LedgerId)
                                          .OrderByDescending(x => x.CreatedDate)
                                          .Select(x => x.IdentifyingCode)
                                          .FirstOrDefaultAsync();

            entity.IdentifyingCode = lastIdentifyingCodeUsed + 1;
            entity.LedgerId        = request.LedgerId;
            await _context.Transactions.AddAsync(entity, cancellationToken);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Пример #25
0
 public async Task Update(Shipment ship, TrackingContext context)
 {
     ship = setUpper(ship);
     context.Entry(ship).State = EntityState.Modified;
     await context.SaveChangesAsync();
 }
Пример #26
0
 public async Task Delete(User user, TrackingContext context)
 {
     context.User.Remove(user);
     await context.SaveChangesAsync();
 }
Пример #27
0
 public async Task Update(User user, TrackingContext context)
 {
     context.Entry(user).State = EntityState.Modified;
     await context.SaveChangesAsync();
 }
Пример #28
0
 public async Task Delete(Shipment ship, TrackingContext context)
 {
     context.Shipment.Remove(ship);
     await context.SaveChangesAsync();
 }
Пример #29
0
 public async Task Close(Shipment ship, TrackingContext context)
 {
     ship.IsClosed             = Contants.CLOSED;
     context.Entry(ship).State = EntityState.Modified;
     await context.SaveChangesAsync();
 }
        public async Task <IActionResult> Send(string id, SeguimientoVM seguimiento)
        {
            if (ModelState.IsValid)
            {
                var invoice = await _api.GetInvoice("http://facturacion-utn-amazon.herokuapp.com", "/api/invoice", id);

                if (invoice == null)
                {
                    return(NotFound());
                }

                var email = User.Identity.Name;

                if (invoice.user_client.email != email)
                {
                    return(Forbid());
                }

                try
                {
                    var now    = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.Local);
                    var tipoT  = seguimiento.PedTipoEnvio.Equals("T");
                    var regalo = seguimiento.PedRegalo.Equals("S");

                    var extra = 0;
                    if (!tipoT)
                    {
                        extra = 5;
                    }

                    if (regalo)
                    {
                        extra += 10;
                    }

                    var pedido = new Pedidos
                    {
                        InvoiceNumber    = id,
                        ClienteEmail     = email,
                        PedTotal         = decimal.Parse(invoice.total),
                        PedFechaEnvio    = now,
                        PedFase          = 'P',
                        PedLugarOrigen   = seguimiento.PedLugarOrigen,
                        PedLugarDestino  = seguimiento.PedLugarDestino,
                        PedEnvioEstandar = tipoT,
                        PedCostoExtra    = extra,
                        PedRegalo        = regalo,
                        PedTarjeta       = seguimiento.PedTarjeta
                    };

                    _context.Add(pedido);
                    await _context.SaveChangesAsync();

                    _flashMessage.Confirmation("Pedido enviado.");

                    return(RedirectToAction(nameof(Index)));
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
            }
            seguimiento.InvoiceNumber = id;

            return(View(seguimiento));
        }