Ejemplo n.º 1
0
        public async Task <IActionResult> PutUserTickets(int id, UserTickets userTickets)
        {
            if (id != userTickets.UserId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <bool> RegistrarUsuario(UserModel user)
        {
            var usuario = new Usuario(user.Login);

            usuario.Nome = user.Nome;
            //usuario.Senha = Crypter.MD5.Crypt(user.Senha);
            usuario.Email        = user.Email;
            usuario.Matricula    = user.Matricula;
            usuario.Telefone     = user.Telefone;
            usuario.BancaInicial = Convert.ToDecimal(user.BancaInicial);
            usuario.BancaAtual   = Convert.ToDecimal(user.BancaInicial);


            try
            {
                await _usuarioRepository.AddAsync(usuario);

                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);

                return(false);
            }
        }
Ejemplo n.º 3
0
 public async Task<IActionResult> Create([Bind("IssueId,Topic,Description,CreateDate,CloseDate")] Issue issue)
 {
     if (ModelState.IsValid)
     {
         _context.Add(issue);
         await _context.SaveChangesAsync();
         return RedirectToAction(nameof(Index));
     }
     return View(issue);
 }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Id,Description,Category,TicketDate")] Ticket ticket)
        {
            if (ModelState.IsValid)
            {
                _context.Add(ticket);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(ticket));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> PutTicket([FromRoute] int ticketId, TicketForm ticketForm)
        {
            // Only owner or team member can update tickets
            var currentUserId = int.Parse(User.Identity.Name);

            if (ticketForm.OwnerId != currentUserId && !User.IsInRole("team"))
            {
                return(Forbid());
            }

            // Receive ticket id from url
            var ticket = await _context.Ticket.FindAsync(ticketId);

            if (ticket == null)
            {
                return(NotFound("Ticket not found"));
            }

            // Modify ticket
            ticket.Title   = ticketForm.Title;
            ticket.Content = ticketForm.Content;

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

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

            return(NoContent());
        }
Ejemplo n.º 6
0
        public async Task <bool> Bet(BetModel model)
        {
            try
            {
                var usuarios = await _usuarioRepository.ObterUsuarios();

                var usuario = usuarios.FirstOrDefault();

                var bet = new Bet()
                {
                    Date  = DateTime.Now,
                    Stake = Convert.ToDecimal(model.Stake),
                    ODD   = Convert.ToDecimal(model.Odd),
                    Green = model.Green,
                };

                bet.Lucro = CalcProfit(bet.Green, bet.Stake, bet.ODD);

                usuario.AtualizarBancaAtual(bet.Lucro);

                var saldo = usuario.BancaInicial + bet.Lucro;
                bet.Porcentagem = (saldo - usuario.BancaInicial) / usuario.BancaInicial * 100;

                //bet.SaldoAtual = usuario.BancaAtual;

                await _betRepository.AddAsync(bet);

                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);

                return(false);
            }
        }
Ejemplo n.º 7
0
        public static async Task <UserRoles> CreateUserRoleAssociation(int newUserId, RoleTitle roleId, HelpDeskContext _context)
        {
            UserRoles newUserRole = new UserRoles()
            {
                UserId = newUserId,
                RoleId = (int)roleId
            };

            // Add user role to database
            _context.UserRoles.Add(newUserRole);
            await _context.SaveChangesAsync();

            return(newUserRole);
        }
        public async Task <IActionResult> Create([Bind("LastName,FirstMidName")] User user)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(user);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }

            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }

            return(View(user));
        }
Ejemplo n.º 9
0
        public static async Task <Ticket> CreateTicket(TicketForm ticketForm, HelpDeskContext _context)
        {
            // Create ticket
            Ticket ticket = new Ticket()
            {
                Title   = ticketForm.Title,
                Content = ticketForm.Content
            };

            // Add ticket to database
            _context.Ticket.Add(ticket);
            await _context.SaveChangesAsync();

            return(ticket);
        }
Ejemplo n.º 10
0
        public static async Task <User> CreateUser(Login login, string hashedPw, HelpDeskContext _context)
        {
            // Create new user object
            User newUser = new User()
            {
                UserName     = login.UserName,
                UserPassword = hashedPw
            };

            // Add user to database
            _context.User.Add(newUser);
            await _context.SaveChangesAsync();

            return(newUser);
        }
Ejemplo n.º 11
0
        public async Task <bool> RegistrarUsuario(string userName)
        {
            var usuario = new Usuario(userName);

            try
            {
                await _usuarioRepository.AddAsync(usuario);

                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);

                return(false);
            }
        }
Ejemplo n.º 12
0
 public async Task Save()
 {
     await _helpDeskContext.SaveChangesAsync();
 }