public async Task <IActionResult> PutDocument([FromRoute] long id, [FromBody] Document document)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != document.DocumentId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Example #2
0
        public async Task <IActionResult> Create([Bind("Name,CategoryId")] Subcategory subcategory)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var subcategories = _context.Subcategories.Where(s => s.Name == subcategory.Name).FirstOrDefault();
                    if (subcategories != null)
                    {
                        ModelState.AddModelError(string.Empty, "This subcategory already exists");
                        return(RedirectToAction("Create", "Subcategories", new { categoryId = subcategory.CategoryId }));
                    }
                    else
                    {
                        _context.Add(subcategory);
                        await _context.SaveChangesAsync();

                        //return RedirectToAction(nameof(Index));
                        return(RedirectToAction("Index", "Subcategories", new { Id = subcategory.CategoryId, name = _context.Categories.Where(c => c.Id == subcategory.CategoryId).FirstOrDefault().Name }));
                    }
                }
            }
            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.");
            }
            //PopulateDepartmentsDropDownList(subcategory.CategoryId);
            return(View(subcategory));
            //return RedirectToAction("Index", "Subcategories", new { id = subcategory.CategoryId, name = _context.Categories.Where(c => c.Id == subcategory.CategoryId).FirstOrDefault().Name });
        }
Example #3
0
        public async Task <IActionResult> PutAspNetRole([FromRoute] string id, [FromBody] AspNetRole aspNetRole)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != aspNetRole.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Example #4
0
        public async Task <T> AddAsync(T entity)
        {
            DbContext.Set <T>().Add(entity);
            await DbContext.SaveChangesAsync();

            return(entity);
        }
Example #5
0
        public async Task <IActionResult> PutCustomer(long id, Customer customer)
        {
            if (id != customer.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutApplicationUser([FromRoute] Guid id, [FromBody] ApplicationUser applicationUser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != applicationUser.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Example #7
0
        public async Task AddAsync(int roleId, int userId)
        {
            var ctxUser = await _context.Users
                          .FirstOrDefaultAsync(u => u.UserId == userId);

            if (ctxUser is null)
            {
                throw new RepositoryException("Not found user");
            }

            var ctxRole = await _context.Roles
                          .FirstOrDefaultAsync(r => r.RoleId == roleId);

            if (ctxRole is null)
            {
                throw new RepositoryException("Not found role");
            }

            var userRole = new UserRole
            {
                Role = ctxRole,
                User = ctxUser
            };

            await _context.UserRoles.AddAsync(userRole);

            await _context.SaveChangesAsync();
        }
Example #8
0
        public async Task <IActionResult> Create([Bind("Info,Date,ProductId,UserId,UserName")] Comment comment, int num, string searchString)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(comment);

                    //User user = await _userMenager.FindByIdAsync(comment.UserId);

                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index", "Comments", new { Id = comment.ProductId, name = _context.Products.Where(c => c.Id == comment.ProductId).FirstOrDefault().Name, num = num, searchString = searchString }));
                }
                else
                {
                    return(RedirectToAction("Create", "Comments", new { productId = comment.ProductId, userId = comment.UserId, num = num, searchString = searchString }));
                }
            }
            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.");
            }
            //PopulateDepartmentsDropDownList(subcategory.CategoryId);
            //return View(subcategory);
            return(RedirectToAction("Index", "Comments", new { Id = comment.ProductId, name = _context.Products.Where(c => c.Id == comment.ProductId).FirstOrDefault().Name, num = num, searchString = searchString }));
        }
        public async Task <IActionResult> Create([Bind("Name")] Category category)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var categories = _context.Categories.Where(c => c.Name == category.Name).FirstOrDefault();
                    if (categories != null)
                    {
                        ModelState.AddModelError(string.Empty, "This category already exists");
                    }
                    else
                    {
                        _context.Add(category);
                        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(category));
        }
Example #10
0
        public async Task <RefreshToken> SaveRefreshToken(RefreshToken token)
        {
            context.RefreshTokens.Add(token);
            await context.SaveChangesAsync();

            return(token);
        }
Example #11
0
        public async Task <IActionResult> Post()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound("The specified user could not be found."));
            }

            using (var rng = new RNGCryptoServiceProvider())
            {
                var data = new byte[16];
                rng.GetBytes(data);

                var token = new ApiToken
                {
                    Token  = Convert.ToBase64String(data),
                    UserId = user.Id
                };

                _context.ApiTokens.Add(token);
                await _context.SaveChangesAsync();

                return(new JsonResult(token));
            }
        }
Example #12
0
        public async Task <long> CreateUserAsync(User user)
        {
            _context.Users.Add(user);
            await _context.SaveChangesAsync();

            return(user.Id);
        }
Example #13
0
        /// <summary>
        /// Turnes the state of the user to false. This is not going to remove the user from database or nullify the asigned roles.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <int> DeleteUser(string id)
        {
            _dbContext.Users.Where(u => u.Id == id).Single().Status = false;
            int num = await _dbContext.SaveChangesAsync();

            return(num);
        }
Example #14
0
        public async Task <bool> CreateBuildingActivity(BuildingActivity buildingActivity)
        {
            _context.Add(buildingActivity);
            var res = await _context.SaveChangesAsync();

            return(res > 0);
        }
Example #15
0
        public async Task <bool> BlockUsersAsync(IEnumerable <int> ids)
        {
            await dbContext.Users.Where(u => ids.Contains(u.Id)).ForEachAsync(u => u.IsBlocked = true);

            await dbContext.SaveChangesAsync();

            return(true);
        }
Example #16
0
        public async Task <IActionResult> Spelen(int?id)
        {
            // meegegeven id en er is iemand ingelogd
            if (id == null || nuSpelend == null)
            {
                return(NotFound());
            }

            var spel = await _context.Spel.FirstOrDefaultAsync(m => m.ID == id);

            if (spel == null)
            {
                return(NotFound());
            }

            var aantal_mensen_in_game = identityContext.Spelers.Where(m => m.Token == spel.Token).Select(m => m.Token).Count();

            if (aantal_mensen_in_game >= 2 && nuSpelend.Token != spel.Token)
            {
                return(NotFound());
            }

            var speler_temp = nuSpelend;

            if (aantal_mensen_in_game == 1 && nuSpelend.Token == spel.Token)
            {
                // maker van spel 'rejoint'
                ViewData["enigeSpeler"]  = true;
                speler_temp.HuidigeKleur = Kleur.Wit;
            }
            else
            {
                // tweede speler joint
                ViewData["enigeSpeler"] = false;

                Speler temp = await identityContext.Spelers.FirstOrDefaultAsync(m => m.Token == spel.Token && m.Email != speler_temp.Email);

                if (temp.HuidigeKleur == Kleur.Wit)
                {
                    speler_temp.HuidigeKleur = Kleur.Zwart;
                }
                else
                {
                    speler_temp.HuidigeKleur = Kleur.Wit;
                }

                //speler_temp.HuidigeKleur = Kleur.Zwart;
            }

            // token van spel wordt gegeven aan de speler
            // speler die meedoet aan een spel krijgt kleur zwart
            speler_temp.Token = spel.Token;
            identityContext.Update(speler_temp);
            await identityContext.SaveChangesAsync();

            spel.Bord = JsonConvert.DeserializeObject <Kleur[, ]>(spel.JsonBord);
            return(View(spel));
        }
Example #17
0
    public async Task <bool> CommitAsync()
    {
        var eventLogs = _context.LogEvents();
        await _context.SaveChangesAsync();

        await PublishEventsAsync(eventLogs);

        return(true);
    }
Example #18
0
        public async Task <T> AddAsync(T entity)
        {
            //_identityContext.BeginTransaction();
            await _identityContext.Set <T>().AddAsync(entity);

            await _identityContext.SaveChangesAsync();

            return(entity);
        }
Example #19
0
        public async Task AddAsync(User user)
        {
            var newUser = user;

            await _context.Users.AddAsync(newUser);

            await _context.SaveChangesAsync();

            await _userRoleRepository.SetDefaultRoleAsync(newUser.UserId);
        }
Example #20
0
        public virtual async Task CreateAsync(TEntity entity)
        {
            entity.Id = entity.Id == Guid.Empty
                ? Guid.NewGuid()
                : entity.Id;
            entity.CreatedAt = DateTime.UtcNow;
            await _dataset.AddAsync(entity);

            await _context.SaveChangesAsync();
        }
Example #21
0
        public async Task <IActionResult> Create([Bind("idPatients,namePatients,phonePatients,gender,health_condition,doctor_id,nurse_id,created")] Patients patients)
        {
            if (ModelState.IsValid)
            {
                _context.Add(patients);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(patients));
        }
        public async Task Register(string route, int?organisationId)
        {
            if (_context.SrnAuthAssignments.Any(a => a.Route == route && a.OrganisationId == organisationId))
            {
                throw new Exception("The authorisation assignment already exists.");
            }

            await _context.AddAsync(new SrnAuthAssignment { Route = route, OrganisationId = organisationId });

            await _context.SaveChangesAsync();
        }
        public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,Email,Password,CreditCard,CarNumber,CarType,Address,PhoneNumber,Balance")] GeneralUser generalUser)
        {
            if (ModelState.IsValid)
            {
                _context.Add(generalUser);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(generalUser));
        }
Example #24
0
        public async Task <IActionResult> Create([Bind("idSpecialite,nameSpecialite")] Specialites specialites)
        {
            if (ModelState.IsValid)
            {
                _context.Add(specialites);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(specialites));
        }
        public async Task <IActionResult> Create([Bind("Id,AbsoluteRefreshTokenLifetime,AccessTokenLifetime,AccessTokenType,AllowAccessTokensViaBrowser,AllowOfflineAccess,AllowPlainTextPkce,AllowRememberConsent,AlwaysIncludeUserClaimsInIdToken,AlwaysSendClientClaims,AuthorizationCodeLifetime,ClientId,ClientName,ClientUri,EnableLocalLogin,Enabled,IdentityTokenLifetime,IncludeJwtId,LogoUri,LogoutSessionRequired,LogoutUri,PrefixClientClaims,ProtocolType,RefreshTokenExpiration,RefreshTokenUsage,RequireClientSecret,RequireConsent,RequirePkce,SlidingRefreshTokenLifetime,UpdateAccessTokenClaimsOnRefresh")] Client client)
        {
            if (ModelState.IsValid)
            {
                _context.Add(client);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(client));
        }
Example #26
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Ingredient ingredient)
        {
            if (ModelState.IsValid)
            {
                _context.Add(ingredient);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(ingredient));
        }
Example #27
0
        public async Task <IActionResult> Create([Bind("Id,Description,DisplayName,Enabled,Name")] ApiResource apiResource)
        {
            if (ModelState.IsValid)
            {
                _context.Add(apiResource);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(apiResource));
        }
Example #28
0
        public async Task <IActionResult> Create([Bind("IdMedConv,NomMedConv,PrenomMedConv,Email,Jours_Usine,PlageHoraire,Honoraire_seance,MobielMedConv,idSpecialite")] MedecinConventionne medecinConventionne)
        {
            if (ModelState.IsValid)
            {
                _context.Add(medecinConventionne);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["idSpecialite"] = new SelectList(_context.Specialites, "idSpecialite", "nameSpecialite", medecinConventionne.idSpecialite);
            return(View(medecinConventionne));
        }
Example #29
0
        public async Task <bool> AddSourceCode(SourceCodeForDisPlay temp)
        {
            if (!VaildationCheck(temp))
            {
                return(false);
            }

            _identityContext.SourceCodes.Add(new SourceCode(temp, false));
            await _identityContext.SaveChangesAsync();

            return(true);
        }
Example #30
0
        public async Task <IActionResult> Create([Bind("Id,Title,Age,Describe,IsDelete")] Mac mac)
        {
            if (ModelState.IsValid)
            {
                _context.Add(mac);
                await _context.SaveChangesAsync();

                Message = "Successfully create mac";
                return(RedirectToAction(nameof(Index)));
            }
            return(View(mac));
        }