Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Price")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
Esempio n. 2
0
        public async Task <bool> AddLogin(AppaAccessLog appaAccessLog)
        {
            using (var context = new testdbContext())
            {
                await context.AppaAccessLog.AddAsync(appaAccessLog);

                return(await context.SaveChangesAsync() > 0);
            }
        }
Esempio n. 3
0
        async Task IUserService.Delete(int UserId)
        {
            using (testdbContext db = new testdbContext())
            {
                //Creo el objeto ->
                User obj = db.User.Find(UserId);

                //Insert ->
                db.User.Remove(obj);
                await db.SaveChangesAsync();
            }
        }
Esempio n. 4
0
        public async Task DoSomethingAsync()
        {
            for (int i = 0; i < 100; i++)
            {
                _testdbContext.Add(new Log()
                {
                    LogData = $"Iteration: {i}  at time: {DateTime.Now}"
                });
            }

            await _testdbContext.SaveChangesAsync();

            //return true;
        }
Esempio n. 5
0
        public async Task <bool> UpdateLogin(AppaAccessLog appaAccessLog)
        {
            using (var context = new testdbContext())
            {
                var login = await context.AppaAccessLog
                            .FirstOrDefaultAsync(l => l.UserId == appaAccessLog.UserId && l.IsActive);

                if (login != null)
                {
                    login.Token           = appaAccessLog.Token;
                    login.RefreshToken    = appaAccessLog.RefreshToken;
                    login.UpdatedDateTime = DateTimeOffset.UtcNow;
                }
                return(await context.SaveChangesAsync() > 0);
            }
        }
Esempio n. 6
0
        async Task<int> IUserService.Insert(UserRequest model)
        {
            using (testdbContext db = new testdbContext())
            {
                //Creo el objeto ->
                User obj = new User();
                obj.UserName = model.UserName;
                obj.Name = model.Name;
                obj.Email = model.Email;
                obj.Phone = model.Phone;

                //Insert ->
                await db.AddAsync(obj);
                await db.SaveChangesAsync();

                return obj.UserId;
            }
        }
Esempio n. 7
0
        async Task IUserService.Upload(UserRequestEdit model)
        {
            using (testdbContext db = new testdbContext())
            {
                //Creo el objeto ->
                User obj = db.User.Find(model.UserId);
                if (obj != null)
                {
                    obj.UserName = model.UserName;
                    obj.Name = model.Name;
                    obj.Email = model.Email;
                    obj.Phone = model.Phone;

                    //Actualizo ->
                    db.Entry(obj).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                    await db.SaveChangesAsync();
                }
                else
                    throw new Exception("El usuerio no existe");
            }
        }