Beispiel #1
0
        public override async Task <StartSetupReply> StartSetup(Empty request, ServerCallContext context)
        {
            bool isInstalled = await IsAlreadyInstalled();

            string?existingAuthKey = await GetSetupAuthKey();

            if (isInstalled || existingAuthKey != null)
            {
                return(new StartSetupReply
                {
                    Success = false,
                });
            }

            string        newAuthKey     = _secureRandom.GetRandomString(16);
            SystemSetting authKeySetting = new SystemSetting
            {
                Name  = AUTH_KEY,
                Value = newAuthKey,
            };

            _authDbContext.Add(authKeySetting);
            await _authDbContext.SaveChangesAsync();

            return(new StartSetupReply
            {
                Success = true,
                AuthToken = newAuthKey,
            });
        }
        public IActionResult Post([FromForm] IFormFile file, int id)
        {
            if (file == null && id == 0)
            {
                return(null);
            }

            ParkingImages model = new ParkingImages();

            using (var memoryStream = new MemoryStream())
            {
                file.CopyToAsync(memoryStream);
                model.Image = memoryStream.ToArray();
            }

            model.Parking = _context.parkings.FirstOrDefault(p => p.ParkingId == id);

            var result = _context.Add(model);

            if (_context.SaveChanges() == 0)
            {
                return(BadRequest());
            }

            return(Ok());
        }
        public async Task <IActionResult> Create([Bind("Id, User, Amount,Semester,Paid")] Payment payment, ClaimsPrincipal principal)
        {
            var users = await _userManager.Users.ToListAsync();

            SelectList list = new SelectList(users);

            ViewBag.Users = list;
            if (User.IsInRole("Admin") && ModelState.IsValid)
            {
                var    nvc       = Request.Form;
                string user_post = nvc["User"];
                //system.diagnostics.debug.writeline(user_post);
                var sameuser = _userManager.Users.FirstOrDefault(u => u.Email == user_post);
                //system.diagnostics.debug.writeline("user is: " + sameuser.email);
                payment.User = sameuser;
            }
            else if (User.IsInRole("Student") && ModelState.IsValid)
            {
                var current_User = _userManager.GetUserAsync(HttpContext.User).Result;
                payment.User = current_User;
            }
            _context.Add(payment);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));

            return(View(payment));
        }
Beispiel #4
0
        public override async Task <CreateLdapCredentialReply> CreateLdapCredential(CreateLdapCredentialRequest request, ServerCallContext context)
        {
            Guid appId  = new Guid(request.Id);
            Guid userId = new Guid(_userManager.GetUserId(context.GetHttpContext().User));

            LdapAppSettings ldapAppSettings = await _authDbContext.LdapAppSettings
                                              .Where(a => a.AuthApp.UserGroups.Any(u => u.Members.Any(m => m.Id == userId)))
                                              .SingleAsync(l => l.AuthApp.Id == appId);

            AppUser user = await _userManager.GetUserAsync(context.GetHttpContext().User);

            string plainTextPassword = _secureRandom.GetRandomString(16);
            string hashedPassword    = _hasher.Hash(plainTextPassword);

            LdapAppUserCredentials credentials = new LdapAppUserCredentials
            {
                HashedPassword  = hashedPassword,
                LdapAppSettings = ldapAppSettings,
                User            = user,
            };

            _authDbContext.Add(credentials);
            await _authDbContext.SaveChangesAsync();

            return(new CreateLdapCredentialReply {
                Password = plainTextPassword
            });
        }
Beispiel #5
0
        public async Task <IActionResult> Create([Bind("Id,ReportedUserId,Reporter,ReportedItemId,Subject")] Report report)
        {
            _context.Add(report);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(ReportFinished)));
        }
Beispiel #6
0
        public override async Task <GrantApplicationReply> GrantApplication(GrantApplicationRequest request, ServerCallContext context)
        {
            AppUser currentUser = await _userManager.GetUserAsync(context.GetHttpContext().User);

            OIDCAppSettings settings = await _authDbContext.OIDCAppSettings
                                       .Where(u => u.ClientId == request.AppId)
                                       // FIXME: add this condition
                                       // .Where(u => u.RedirectUrl == request.RedirectUri)
                                       .Where(u => u.AuthApp.UserGroups.Any(u => u.Members.Contains(currentUser)))
                                       .SingleAsync();

            OIDCSession session = new OIDCSession
            {
                CreationTime    = SystemClock.Instance.GetCurrentInstant(),
                OIDCAppSettings = settings,
                User            = currentUser,
                Nonce           = request.Nonce,
            };

            _authDbContext.Add(session);
            await _authDbContext.SaveChangesAsync();

            // TODO: encrypt this
            string accessToken = session.Id.ToString();

            return(new GrantApplicationReply
            {
                Success = true,
                AccessToken = accessToken,
            });
        }
Beispiel #7
0
        public async Task MarkInvalidLoginAttemptAsync(IPAddress ipAddress, string userAgent, string userName)
        {
            AppUser?user = await _userManager.FindByNameAsync(userName);

            InvalidLoginAttempt attempt = new InvalidLoginAttempt
            {
                UserName    = userName,
                TargetUser  = user,
                UserAgent   = userAgent,
                IpAddress   = ipAddress,
                AttemptTime = SystemClock.Instance.GetCurrentInstant(),
            };

            _authDbContext.Add(attempt);
            await _authDbContext.SaveChangesAsync();
        }
        public async Task <IActionResult> Create([Bind("ID,adi,soyadi,adres,Ulkesi,ResimDosyası")] Ogrenci ogrenci)
        {
            if (ModelState.IsValid)
            {
                _context.Add(ogrenci);

                string resimler = Path.Combine(_environment.WebRootPath, "resimler");
                if (ogrenci.ResimDosyası.Length > 0)
                {
                    using (var fileStream = new FileStream(Path.Combine(resimler, ogrenci.ResimDosyası.FileName), FileMode.Create))
                    {
                        await ogrenci.ResimDosyası.CopyToAsync(fileStream);
                    }
                }
                else
                {
                    System.Console.WriteLine("Null Exception Error!!");
                }

                ogrenci.ResimYolu = ogrenci.ResimDosyası.FileName;

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(ogrenci));
        }
        //database relationships
        public TermGrade InitializeGrades(string term)
        {
            var termGrade = new TermGrade
            {
                Term  = term,
                Grade = 0
            };

            string[] types = { "Quiz1", "Quiz2", "Quiz3", "Assignment1", "Assignment2", "Assignment3" };

            var item = new QuizOrAssignment();

            for (int i = 0; i < types.Length; i++)
            {
                item = new QuizOrAssignment
                {
                    Grade = 0,
                    Type  = types[i]
                };

                authDbContext.Add(item);
                authDbContext.SaveChanges();

                switch (i)
                {
                case 0:
                    termGrade.Quiz1ID = item.ID;
                    break;

                case 1:
                    termGrade.Quiz2ID = item.ID;
                    break;

                case 2:
                    termGrade.Quiz3ID = item.ID;
                    break;

                case 3:
                    termGrade.Assignment1ID = item.ID;
                    break;

                case 4:
                    termGrade.Assignment2ID = item.ID;
                    break;

                case 5:
                    termGrade.Assignment3ID = item.ID;
                    break;

                default:
                    break;
                }
            }

            return(termGrade);
        }
Beispiel #10
0
        public WebAPIResult CreateAndBindOpen(string appId)
        {
            WebAPIResult result = new WebAPIResult()
            {
                Success = true
            };
            string openAppId = string.Empty;

            try
            {
                var author = db.WechatOpenAuthorizer.FirstOrDefault(p => p.AuthorizerAppId == appId && !p.IsDel);
                if (author == null)
                {
                    result.Success = false;
                    result.Message = " WechatOpenAuthorizer is null";
                    return(result);
                }

                var createResult = Senparc.Weixin.Open.MpAPIs.Open.OpenApi.Create(author.AuthorizerAccessToken, appId);
                if (createResult.errcode != ReturnCode.请求成功 && createResult.errcode != ReturnCode.该公众号_小程序已经绑定了开放平台帐号)
                {
                    result.Success = false;
                    result.Message = createResult.errmsg;
                }
                else if (createResult.errcode == ReturnCode.请求成功)
                {
                    openAppId = createResult.open_appid;
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
                if (ex.Message.Contains("89000"))
                {
                    result.Success = true;
                }
            }
            var bind = db.WechatOpenBind.FirstOrDefault(p => p.AppId == appId);

            if (bind == null)
            {
                bind = new WechatOpenBind()
                {
                    AppId     = appId,
                    OpenAppId = openAppId
                };
                db.Add(bind);
            }
            bind.BindDesc = result.Message;
            bind.AddTime  = DateTime.Now;
            bind.IsBind   = result.Success;
            db.SaveChanges();

            return(result);
        }
        public bool CreateUser(User user)
        {
            var createdUser = _context.Add(user);

            if (_context.SaveChanges() > 0)
            {
                return(true);
            }
            return(false);
        }
Beispiel #12
0
        public IActionResult Create(Song song)
        {
            try
            {
                List <String> listExt = new List <String>()
                {
                    "mp3", "wav", "m4a", "flac", "mp4", "wma", "aac"
                };
                var Files = Request.Form.Files;

                foreach (var file in Files)
                {
                    var songs = Path.Combine(hostingEnvironment.WebRootPath, "songs");
                    if (file.Length > 0)
                    {
                        string filename     = Guid.NewGuid().ToString();
                        var    old_filename = file.FileName.Split('.');
                        var    extension    = old_filename.Last().ToLower();

                        if (listExt.Contains(extension) == false)
                        {
                            ViewData["error_file_type"] = "You have send a non authorized type file";
                            return(View());
                        }

                        song.PathFileSong = filename + "." + extension;
                        using (var fileStream = new FileStream(Path.Combine(songs, song.PathFileSong), FileMode.Create))
                        {
                            file.CopyTo(fileStream);
                        }
                        _context.Add(song);
                        _context.SaveChanges();
                    }
                }

                return(View());
            }
            catch
            {
                return(View());
            }
        }
        public async Task <IActionResult> Create([Bind("ProductId,ProductNumber,ProductName,ProductDescription,ProductCategory,Price,Date")] ProductsModel productModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(productModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(productModel));
        }
        public async Task <IActionResult> Create([Bind("MarkId,TotalMark")] Mark mark, string product, string user)
        {
            List <SelectListItem> users = new List <SelectListItem>();

            foreach (var userValue in _context.Users)
            {
                users.Add(new SelectListItem()
                {
                    Value = userValue.UserName, Text = userValue.UserName
                });
            }
            ViewBag.Users = users;

            List <SelectListItem> products = new List <SelectListItem>();

            foreach (var productValue in _context.Products)
            {
                products.Add(new SelectListItem()
                {
                    Value = productValue.ProductName, Text = productValue.ProductName
                });
            }
            ViewBag.Products = products;

            if (mark.TotalMark > 5 || mark.TotalMark < 0)
            {
                StatusMessage = "Error. Invalid range for total mark.";
                return(RedirectToAction());
            }
            ApplicationUser findUser    = _context.Users.Where(value => value.UserName == user).First();
            Product         findProduct = _context.Products.Where(value => value.ProductName == product).First();

            if (findUser != null && findProduct != null)
            {
                mark.User    = findUser;
                mark.Product = findProduct;
            }
            else
            {
                StatusMessage = "Not all properties choosen";
                return(RedirectToAction());
            }

            if (ModelState.IsValid)
            {
                _context.Add(mark);
                await _context.SaveChangesAsync();

                StatusMessage = "Mark has been added";
                return(RedirectToAction(nameof(Index)));
            }
            StatusMessage = "Error. Invalid form.";
            return(View(mark));
        }
Beispiel #15
0
        public async Task <IActionResult> Create([Bind("VendorNumber,VendorName,VendorAddress,Amount,Date")] VendorTransactionModel vendorTransactionModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vendorTransactionModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vendorTransactionModel));
        }
        public async Task <IActionResult> Create([Bind("ID,Name,DbConnectionString")] Branch branch)
        {
            if (ModelState.IsValid)
            {
                _context.Add(branch);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(branch));
        }
Beispiel #17
0
        public IActionResult Put(int id, ParkingProfileViewModel model)
        {
            if (id == 0 && model == null)
            {
                return(null);
            }

            var parking = _dbContext.parkings
                          .FirstOrDefault(p => p.ParkingId == id);
            var facilities = _dbContext.ParkingFacilities
                             .FirstOrDefault(p => p.Parking.ParkingId == parking.ParkingId);

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



            parking.Name        = model.Name;
            parking.Description = model.Description;
            parking.City        = model.City;
            parking.Address     = model.Address;

            var result = _dbContext.Update(parking);

            if (_dbContext.SaveChanges() > 0)
            {
                if (facilities == null)
                {
                    var facility = new ParkingFacilities()
                    {
                        Parking        = parking,
                        GuestRoom      = model.GuestRoom,
                        OnlinePayment  = model.OnlinePayment,
                        ServiceStation = model.ServiceStation
                    };

                    _dbContext.Add(facilities);
                    _dbContext.SaveChanges();
                }
                else
                {
                    facilities.ServiceStation = model.ServiceStation;
                    facilities.OnlinePayment  = model.OnlinePayment;
                    facilities.GuestRoom      = model.GuestRoom;
                    _dbContext.Update(facilities);
                    _dbContext.SaveChanges();
                }
            }


            return(Ok());
        }
Beispiel #18
0
        private async Task <string> SetNewAuthToken()
        {
            SystemSetting?authKeySetting = await _authDbContext.SystemSettings
                                           .SingleOrDefaultAsync(s => s.Name == AUTH_KEY);

            string newAuthKey = _secureRandom.GetRandomString(16);

            if (authKeySetting == null)
            {
                authKeySetting = new SystemSetting
                {
                    Name = AUTH_KEY,
                };
                _authDbContext.Add(authKeySetting);
            }
            authKeySetting.Value = newAuthKey;

            await _authDbContext.SaveChangesAsync();

            return(newAuthKey);
        }
        public async Task <IActionResult> Create([Bind("name,make,year,price,os")] Phone phone)
        {
            if (ModelState.IsValid)
            {
                _context.Add(phone);
                await _context.SaveChangesAsync();

                return(View());
            }

            return(View());
        }
        public async Task <IActionResult> Create([Bind("Id,PostText,PostImage,PublicDate,UserId")] Post post)
        {
            if (ModelState.IsValid)
            {
                _context.Add(post);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", post.UserId);
            return(View(post));
        }
        public async Task <IActionResult> Create([Bind("id,question,option1,option2,option3,option4,ans,ExamId")] Questions questions)
        {
            if (ModelState.IsValid)
            {
                _context.Add(questions);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ExamId"] = new SelectList(_context.Exams, "id", "AppUserId", questions.ExamId);
            return(View(questions));
        }
        public async Task <IActionResult> Create([Bind("caseName,casePrice,caseColor")] Case cases)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cases);
                await _context.SaveChangesAsync();

                return(View());
            }

            return(View());
        }
Beispiel #23
0
        public IActionResult Create(Playlist playlist)
        {
            ClaimsPrincipal currentUser   = this.User;
            var             currentUserID = currentUser.FindFirst(ClaimTypes.NameIdentifier).Value;

            playlist.userID = currentUserID;
            _context.Add(playlist);
            _context.SaveChanges();

            Index();
            return(View("Index"));
        }
Beispiel #24
0
        public async Task <IActionResult> Create([Bind("Id,MessageText,DateOfMessage,UserSenderId,UserReceiverId")] Message message)
        {
            if (ModelState.IsValid)
            {
                _context.Add(message);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserReceiverId"] = new SelectList(_context.Users, "Id", "Id", message.UserReceiverId);
            return(View(message));
        }
        public async Task <IActionResult> Create([Bind("Id,FriendSenderId,FriendReceiverId")] Friend friend)
        {
            if (ModelState.IsValid)
            {
                _context.Add(friend);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FriendSenderId"] = new SelectList(_context.Users, "Id", "Id", friend.FriendSenderId);
            return(View(friend));
        }
        public async Task <IActionResult> Create([Bind("Id,CommentText,CommentDate,PostId,UserId")] Comment comment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(comment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PostId"] = new SelectList(_context.Posts, "Id", "Id", comment.PostId);
            ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", comment.UserId);
            return(View(comment));
        }
        public async Task <IActionResult> Create([Bind("id,Subject,Description,StartTime,EndTime,AppUserId,GroupId")] Exam exam)
        {
            if (ModelState.IsValid)
            {
                _context.Add(exam);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", new { id = exam.id }));
            }
            ViewData["AppUserId"] = new SelectList(_context.AppUsers, "Id", "Id", exam.AppUserId);
            ViewData["GroupId"]   = new SelectList(_context.Groups, "id", "AppUserId", exam.GroupId);
            return(View(exam));
        }
        public async Task <IActionResult> Create([Bind("Id,Title,CurrentDate,CurrentText")] Guest guest)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.GetUserAsync(User);

                guest.ApplicationUserId = user.Id;
                _context.Add(guest);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(guest));
        }
        public async Task <ActionResult> Create(UserTask newTask)
        {
            if (ModelState.IsValid)
            {
                context.Add(newTask);
                await context.SaveChangesAsync();

                TempData["Success"] = "Успешно добавяне на нова задача";

                return(RedirectToAction("Index"));
            }

            return(View(newTask));
        }
 public bool Save(Category category)
 {
     try
     {
         _context.Add(category);
         _context.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         _logger.LogInformation(e.Message);
         return(false);
     }
 }