Ejemplo n.º 1
0
 private bool AuthenticateUser(string loginId, string password)
 {
     bool result = false;
     using (SessionContext ctx = new SessionContext())
     {
         UserBroker broker_user = new UserBroker(ctx);
         DataModel.User user = broker_user.GetByLoginId(loginId);
         if (user != null && user.Password == password)
         {
             // Session log
             DataModel.UserSession session = new DataModel.UserSession();
             session.Browser = Request.Browser.Browser;
             session.IP = Request.UserHostAddress;
             session.LogonDateTime = DateTime.Now;
             session.User = user;
             DataBroker broker_session = new DataBroker(ctx);
             session = broker_session.Save<DataModel.UserSession>(session);
             user.LastLogonTime = DateTime.Now;
             broker_user.Save(user);
             result = true;
             Session["CurrentUser"] = user;
             Session["CurrentSession"] = session;
         }
     }
     return result;
 }
Ejemplo n.º 2
0
        public async Task <ActionResult <Institution> > GetById([FromServices] DataBroker Context, int id)
        {
            try
            {
                var institution = await Context.Institutions.FirstOrDefaultAsync(x => x.id == id);

                if (institution == null)
                {
                    return(Ok("Institution not found!"));
                }

                return(institution);
            }
            catch (System.Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to request on database"));
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <List <Institution> > > Get([FromServices] DataBroker Context)
        {
            try
            {
                var Institutions = await Context.Institutions.ToListAsync();

                if (Institutions.Count == 0)
                {
                    return(Ok("Institutions not Found!"));
                }

                return(Institutions);
            }
            catch (System.Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to request on database"));
            }
        }
        public async Task <ActionResult <Client> > Post([FromServices] DataBroker Context, [FromBody] Client model)
        {
            var valid = Validacoes.ValidaCPF(model.cpf);

            if (!valid)
            {
                return(Ok("CPF is Invalid!"));
            }

            if (ModelState.IsValid)
            {
                Context.Clients.Add(model);
                await Context.SaveChangesAsync();

                return(model);
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Ejemplo n.º 5
0
        public async Task <ActionResult <Institution> > Post([FromServices] DataBroker Context, [FromBody] Institution model)
        {
            var valid = Validacoes.ValidaCNPJ(model.cnpj);

            if (!valid)
            {
                return(Ok("CNPJ is Invalid!"));
            }

            if (ModelState.IsValid)
            {
                Context.Institutions.Add(model);
                await Context.SaveChangesAsync();

                return(model);
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
        public async Task <ActionResult <Client> > Delete([FromServices] DataBroker Context, int id)
        {
            try
            {
                var client = await Context.Clients.FirstOrDefaultAsync(x => x.id == id);

                if (client == null)
                {
                    return(Ok("Client not found!"));
                }

                var delete_client = Context.Remove(client);

                await Context.SaveChangesAsync();

                return(client);
            }
            catch (System.Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to request on database"));
            }
        }
Ejemplo n.º 7
0
        public async Task <ActionResult <Ticket> > Put([FromServices] DataBroker Context, int id, Ticket model)
        {
            try
            {
                var tickets = await Context.Tickets.FirstOrDefaultAsync(x => x.id_ticket == id);

                if (tickets == null)
                {
                    return(Ok("Ticket not found!"));
                }

                tickets.price    = model.price;
                tickets.type     = model.type;
                tickets.event_id = model.event_id;

                await Context.SaveChangesAsync();

                return(tickets);
            }
            catch (System.Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to request on database"));
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LoadPageLazyUserData"/> class.
 /// </summary>
 /// <param name="serviceLocator">
 /// The service locator.
 /// </param>
 /// <param name="dbBroker">
 /// The db broker.
 /// </param>
 public LoadPageLazyUserData([NotNull] IServiceLocator serviceLocator, [NotNull] DataBroker dbBroker)
 {
     this._dbBroker      = dbBroker;
     this.ServiceLocator = serviceLocator;
 }