コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        public async Task <LikeResult> AddLike(Like like)
        {
            using (var AuthDbContext = new AuthDbContext())
            {
                var isLiked = AuthDbContext.Likes.Where(X => X.PostID == like.PostID && X.UserID == like.UserID).ToList();

                if (isLiked.Count == 0)//daha önceden beğenmediyse beğen.
                {
                    AuthDbContext.Likes.Add(like);
                    await AuthDbContext.SaveChangesAsync();

                    return(new LikeResult {
                        IsSuccess = true, Massage = "Successfully Liked"
                    });
                }


                AuthDbContext.Likes.Remove(isLiked[0]);//daha önceden beğendisye beğenisini kaldır.
                await AuthDbContext.SaveChangesAsync();

                return(new LikeResult {
                    IsSuccess = false, Massage = "Successfully Disliked"
                });
            }
        }
コード例 #4
0
        public async Task <ActionResult <EducationInfo> > PostEducationInfos(EducationInfo educationInfo)
        {
            _context.EducationInfos.Add(educationInfo);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(EducationInfo), new { id = educationInfo.Id }, educationInfo));
        }
コード例 #5
0
        public async Task <IActionResult> Register(string userName, string password, string name, string lastName)
        {
            var user = new ApplicationUser
            {
                Name     = name,
                Access   = "Customer",
                LastName = lastName,
                UserName = userName,
            };

            var result = await userManager.CreateAsync(user, password);

            if (result.Succeeded)
            {
                user = await userManager.FindByNameAsync(user.UserName);

                await authDbContext.AddRangeAsync();

                await authDbContext.SaveChangesAsync();

                var cusInfo = new cusInfo
                {
                    AppUserID = user.Id,
                };

                await authDbContext.AddAsync(cusInfo);

                await authDbContext.SaveChangesAsync();
            }

            return(RedirectToAction("Index", "Customer", new { area = "" }));
        }
コード例 #6
0
        public async Task <IActionResult> PutSlot(int id, Slot slot)
        {
            if (id != slot.SlotId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutParking(int id, Parking parking)
        {
            if (id != parking.ParkingId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #8
0
        public async Task <ActionResult <FamilyData> > PostFamilyData(FamilyData familyData)
        {
            _context.FamilyDatas.Add(familyData);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(FamilyData), new { id = familyData.Id }, familyData));
        }
コード例 #9
0
        public async Task <IActionResult> Edit(int id, [Bind("caseId,caseName,casePrice,caseColor")] Case cases)
        {
            if (id != cases.caseId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(cases);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CaseExists(cases.caseId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            CaseListViewModel casesListViewModel = new CaseListViewModel();

            casesListViewModel.Cases = _caseRepository.List();
            return(View(casesListViewModel));
        }
        public async Task <ActionResult <WorkingExperience> > PostWorkingExperience(WorkingExperience workingExperience)
        {
            _context.WorkingExperiences.Add(workingExperience);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(WorkingExperience), new { id = workingExperience.Id }, workingExperience));
        }
コード例 #11
0
        public async Task <IUser> AddAsync(IUser user)
        {
            try
            {
                if (GetByNameAsync(user.UserName).Result != null)
                {
                    return(null);
                }
                var toAdd = new User()
                {
                    UserName       = user.UserName,
                    PasswordDigest = user.PasswordDigest,
                    PasswordSalt   = user.PasswordSalt
                };

                await _context.User.AddAsync(toAdd);

                await _context.SaveChangesAsync();

                return(user);
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);
            }

            return(null);
        }
コード例 #12
0
        public async Task <ActionResult <AccountProfile> > PostAccountProfile(AccountProfile accountProfile)
        {
            _context.AccountProfiles.Add(accountProfile);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(AccountProfile), new { id = accountProfile.Id }, accountProfile));
        }
コード例 #13
0
        public async Task <string> NewRefreshToken(string clientId, string username, string accessToken)
        {
            var refreshTokenExpiration = config.GetValue <int>("RefreshToken:Expiration");

            var newRefreshTokenString = GenerateRefreshTokenString();

            var newRefreshToken = new RefreshToken();

            newRefreshToken.Id              = newRefreshTokenString;
            newRefreshToken.ClientId        = clientId;
            newRefreshToken.Subject         = username;
            newRefreshToken.ProtectedTicket = accessToken;
            newRefreshToken.IssuedUtc       = DateTime.UtcNow;
            newRefreshToken.ExpiresUtc      = DateTime.UtcNow.AddSeconds(refreshTokenExpiration);

            var existingToken = authDb.RefreshTokens.SingleOrDefault(r => r.Subject == newRefreshToken.Subject && r.ClientId == newRefreshToken.ClientId);

            if (existingToken != null)
            {
                authDb.RefreshTokens.Remove(existingToken);
            }

            authDb.RefreshTokens.Add(newRefreshToken);

            await authDb.SaveChangesAsync();

            return(newRefreshTokenString);
        }
コード例 #14
0
        public async Task <ActionResult <Payroll> > PostPayrolls([FromBody] PayrollFormViewModel payroll)
        {
            VerifyUser();
            var model = new Payroll()
            {
                Salary            = payroll.Salary,
                Tax               = payroll.Tax,
                BPJSKesehatan     = payroll.BPJSKesehatan,
                BPJSTenagaKerja   = payroll.BPJSTenagaKerja,
                NPWP              = payroll.NPWP,
                NameBankAccount   = payroll.NameBankAccount,
                Bank              = payroll.Bank,
                BankAccountNumber = payroll.BankAccountNumber,
                BankBranch        = payroll.BankBranch,
                BackDatedPayment  = payroll.BackDatedPayment,
                Allowance         = payroll.Allowance,
                Incentive         = payroll.Incentive,
                PaidLeave         = payroll.PaidLeave,
                UnPaidLeave       = payroll.UnPaidLeave,
                SalaryPeriod      = payroll.SalaryPeriod,
                Month             = payroll.Month,
                Year              = payroll.Year,
                TakeHomePay       = payroll.TakeHomePay
            };

            EntityExtension.FlagForCreate(model, _identityService.Username, UserAgent);
            _context.Payrolls.Add(model);
            await _context.SaveChangesAsync();

            return(Created("", model));
        }
コード例 #15
0
        public async Task <IActionResult> Deleted(string id)
        {
            var student = await authDbContext.ApplicationUsers.FindAsync(id);

            authDbContext.ApplicationUsers.Remove(student);
            await authDbContext.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
コード例 #16
0
        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));
        }
コード例 #17
0
        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));
        }
コード例 #18
0
        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));
        }
コード例 #19
0
        public async Task <int> CreateAsync(Role model)
        {
            EntityExtension.FlagForCreate(model, IdentityService.Username, UserAgent);
            foreach (var item in model.Permissions)
            {
                EntityExtension.FlagForCreate(item, IdentityService.Username, UserAgent);
            }
            DbSet.Add(model);

            return(await DbContext.SaveChangesAsync());
        }
コード例 #20
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));
        }
コード例 #21
0
        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));
        }
コード例 #22
0
        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());
        }
コード例 #23
0
        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));
        }
コード例 #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));
        }
コード例 #25
0
        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));
        }
コード例 #26
0
        public async Task <ActionResult <AccountInformation> > PostAccountInformations([FromBody] AccountProfileFormViewModel accountProfile)
        {
            VerifyUser();
            var model = new AccountInformation()
            {
                Fullname        = accountProfile.Fullname,
                EmployeeID      = accountProfile.EmployeeId,
                Username        = accountProfile.Username,
                Dob             = accountProfile.DOB,
                Gender          = accountProfile.Gender,
                Religion        = accountProfile.Religion,
                Email           = accountProfile.Email,
                Password        = accountProfile.Password,
                JobTitleName    = accountProfile.JobTitlename,
                Department      = accountProfile.Departmanet,
                Status          = accountProfile.Status,
                JoinDate        = accountProfile.JoinDate,
                CoorporateEmail = accountProfile.CoorporateEmail,
                SkillSet        = accountProfile.SkillSet,
            };

            EntityExtension.FlagForCreate(model, _identityService.Username, UserAgent);
            _context.AccountInformations.Add(model);

            var assetmodel = new Asset()
            {
                AssetName   = accountProfile.AssetName,
                AssetNumber = accountProfile.AssetNumber
            };

            EntityExtension.FlagForCreate(assetmodel, _identityService.Username, UserAgent);
            _context.Assets.Add(assetmodel);

            var payrollmodel = new Payroll()
            {
                Salary            = accountProfile.Salary,
                Tax               = accountProfile.Tax,
                BPJSKesehatan     = accountProfile.BPJSKesehatan,
                BPJSTenagaKerja   = accountProfile.BPJSTenagakerja,
                NPWP              = accountProfile.NPWP,
                NameBankAccount   = accountProfile.NameBankAccount,
                Bank              = accountProfile.Bank,
                BankAccountNumber = accountProfile.BankAccountNumber,
                BankBranch        = accountProfile.BankBranch
            };

            EntityExtension.FlagForCreate(payrollmodel, _identityService.Username, UserAgent);
            _context.Payrolls.Add(payrollmodel);

            await _context.SaveChangesAsync();

            return(Created("", model));
        }
コード例 #27
0
        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));
        }
コード例 #28
0
        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));
        }
コード例 #29
0
        public async Task <int> CreateAsync(Account model)
        {
            EntityExtension.FlagForCreate(model, IdentityService.Username, UserAgent);
            EntityExtension.FlagForCreate(model.AccountProfile, IdentityService.Username, UserAgent);
            foreach (var item in model.AccountRoles)
            {
                item.Role = null;
                EntityExtension.FlagForCreate(item, IdentityService.Username, UserAgent);
            }
            model.Password = SHA1Encrypt.Hash(model.Password);
            DbSet.Add(model);

            return(await DbContext.SaveChangesAsync());
        }
コード例 #30
0
        public async Task <IActionResult> Delete(string id)
        {
            var bookFromDb = await _db.Books.FirstOrDefaultAsync(u => u.Id == id);

            if (bookFromDb == null)
            {
                return(Json(new { success = false, message = "Error while Deleting" }));
            }

            _db.Books.Remove(bookFromDb);
            await _db.SaveChangesAsync();

            return(Json(new { success = true, message = "Delete successful" }));
        }