Beispiel #1
0
        public EAdminUser GetByID(string id)
        {
            using var context = new SMySQLContext();
            EAdminUser e = context.AdminUsers.SingleOrDefault(x => x.Id == id);

            return(e);
        }
Beispiel #2
0
        public async Task <bool> RemoveAsync(string id)
        {
            using var context = new SMySQLContext();
            EAdminUser e = context.AdminUsers.SingleOrDefault(x => x.Id == id);

            if (e == null)
            {
                return(false);
            }
            context.Remove(e);
            await context.SaveChangesAsync();

            return(true);
        }
Beispiel #3
0
        public EAdminUser Authenticate(EAdminUser e)
        {
            using var context = new SMySQLContext();

            //var eUser = new EAdminUser { Email = "*****@*****.**", Password = "******" };
            //eUser.Id = Guid.NewGuid().ToString();
            //eUser.CreationDateUTC = DateTime.UtcNow;
            //context.AdminUsers.Add(eUser);
            //context.SaveChanges();

            var eAdminUser = context.AdminUsers.FirstOrDefault(x => x.Email == e.Email && x.Password == e.Password);

            return(eAdminUser);
        }
        public async Task <string> Save(EAdminUser eAdminUser)
        {
            SDefines.Loading = true;
            HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Put, $"api/v1/SAdminUsers/Save");

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

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

            return(responseBody);
        }
        public async Task <EAdminUser> GetByID(string id)
        {
            SDefines.Loading = true;
            HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Get, $"api/v1/SAdminUsers/GetByID/{id}");

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

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

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

            return(result);
        }
Beispiel #6
0
        //=====================================================GETS ABOVE=====================================================

        #region SaveAsync
        public async Task <string> SaveAsync(EAdminUser eAdminUser)
        {
            eAdminUser.ModificationDateUTC = DateTime.UtcNow;
            using var context = new SMySQLContext();
            if (string.IsNullOrEmpty(eAdminUser.Id))
            {
                eAdminUser.Id = Guid.NewGuid().ToString();
                eAdminUser.CreationDateUTC = DateTime.UtcNow;
                var e = await context.AdminUsers.AddAsync(eAdminUser);

                await context.SaveChangesAsync();

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

                return(e.Entity.Id);
            }
        }
        [ProducesResponseType(StatusCodes.Status400BadRequest)]  // BadRequest
        public async Task <ActionResult <string> > Save([FromBody] EAdminUser eAdminUser)
        {
            var result = await adminUsersService.SaveAsync(eAdminUser);

            return(Ok(result));
        }
        public ActionResult <EAdminUser> Authenticate([FromBody] EAdminUser eAdminUser)
        {
            var e = adminUsersService.Authenticate(eAdminUser);

            return(Ok(e));
        }