Exemplo n.º 1
0
 public IActionResult GetByID(string id)
 {
     using (var context = new SMySQLContext()) {
         ECompanyAdminUser e = context.CompanyUsers.FirstOrDefault <ECompanyAdminUser>(x => x.id == id);
         e.password = "";
         return(Ok(e));
     }
 }
Exemplo n.º 2
0
 public IActionResult Authenticate(string email, string password)
 {
     using (var context = new SMySQLContext()) {
         ECompanyAdminUser eCompany = context.CompanyUsers.FirstOrDefault(x => x.email == email && x.password == password);
         if (eCompany == null)
         {
             return(null);
         }
         return(Ok(eCompany));
     }
 }
Exemplo n.º 3
0
        public async Task <IActionResult> Remove(string id)
        {
            using (var context = new SMySQLContext()) {
                ECompanyAdminUser eCompanyUser = context.CompanyUsers.SingleOrDefault(x => x.id == id);
                if (eCompanyUser == null)
                {
                    return(Ok(false));
                }
                context.Remove(eCompanyUser);
                await context.SaveChangesAsync();

                return(Ok(true));
            }
        }
Exemplo n.º 4
0
        //=====================================================GETS ABOVE=====================================================

        #region Authenticate
        public ECompanyAdminUser Authenticate(ECompanyAdminUser e)
        {
            using var context = new SMySQLContext();

            //var eUser = new ECompanyAdminUser { Name = "Bruno", Email="*****@*****.**", Password="******", CompanyId = "3137acad-f0a2-475e-94f7-859849ed9172" };
            //eUser.Id = Guid.NewGuid().ToString();
            //eUser.CreationDateUTC = DateTime.UtcNow;
            //eUser.ModificationDateUTC = DateTime.UtcNow;
            //context.CompanyAdminUsers.Add(eUser);
            //context.SaveChanges();

            var eClient = context.CompanyAdminUsers.FirstOrDefault(x => x.Email == e.Email && x.Password == e.Password);

            return(eClient);
        }
Exemplo n.º 5
0
        public async Task <string> Save(ECompanyAdminUser eCompanyAdminUser)
        {
            ClientDefines.Loading = true;
            HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Put, $"api/v1/SCompaniesAdminUsers/Save");

            req.Headers.Add("Authorization", $"bearer {ClientDefines.Token}");
            req.Content = new StringContent(JsonConvert.SerializeObject(eCompanyAdminUser), Encoding.UTF8, "application/json");
            var response = await httpClient.SendAsync(req);

            ClientDefines.Loading = false;
            if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
            {
                throw new UnauthorizedAccessException();
            }
            response.EnsureSuccessStatusCode();
            string responseBody = await response.Content.ReadAsStringAsync();

            return(responseBody);
        }
Exemplo n.º 6
0
        public async Task <ECompanyAdminUser> GetByID(string id)
        {
            ClientDefines.Loading = true;
            HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Get, $"api/v1/SCompaniesAdminUsers/GetByID/{id}");

            req.Headers.Add("Authorization", $"bearer {ClientDefines.Token}");
            var response = await httpClient.SendAsync(req);

            ClientDefines.Loading = false;
            if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
            {
                throw new UnauthorizedAccessException();
            }
            response.EnsureSuccessStatusCode();
            string responseBody = await response.Content.ReadAsStringAsync();

            ECompanyAdminUser result = JsonConvert.DeserializeObject <ECompanyAdminUser>(responseBody);

            return(result);
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Save([FromBody] ECompanyAdminUser eUser)
        {
            using (var context = new SMySQLContext()) {
                if (string.IsNullOrEmpty(eUser.id))
                {
                    var e = await context.CompanyUsers.AddAsync(eUser);

                    await context.SaveChangesAsync();

                    return(Ok(e.Entity.id));
                }
                else
                {
                    var e = context.CompanyUsers.Update(eUser);
                    await context.SaveChangesAsync();

                    return(Ok(e.Entity.id));
                }
            }
        }
Exemplo n.º 8
0
        public async Task <string> SaveAsync(ECompanyAdminUser eCompanyAdminUser)
        {
            eCompanyAdminUser.ModificationDateUTC = DateTime.UtcNow;
            using var context = new SMySQLContext();
            if (string.IsNullOrEmpty(eCompanyAdminUser.Id))
            {
                eCompanyAdminUser.Id = Guid.NewGuid().ToString();
                eCompanyAdminUser.CreationDateUTC = DateTime.UtcNow;
                var e = await context.CompanyAdminUsers.AddAsync(eCompanyAdminUser);

                await context.SaveChangesAsync();

                return(e.Entity.Id);
            }
            else
            {
                var e = context.CompanyAdminUsers.Update(eCompanyAdminUser);
                await context.SaveChangesAsync();

                return(e.Entity.Id);
            }
        }
        [ProducesResponseType(StatusCodes.Status400BadRequest)]  // BadRequest
        public async Task <IActionResult> Save([FromBody] ECompanyAdminUser eCompanyAdminUser)
        {
            var result = await service.SaveAsync(eCompanyAdminUser);

            return(Ok(result));
        }
        public ActionResult <ECompanyAdminUser> Authenticate([FromBody] ECompanyAdminUser eCompanyAdminUser)
        {
            var e = service.Authenticate(eCompanyAdminUser);

            return(Ok(e));
        }