コード例 #1
0
        public async Task <IActionResult> Create([Bind("PersonnelID,Email,Name,PhoneNumber,Position,ProjectID")] Personnel personnel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(personnel);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["ProjectID"] = new SelectList(_context.Projects, "ProjectID", "ProjectTitle", personnel.ProjectID);
            return(View(personnel));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("AssetID,AssetAllocated,AssetAnualTestDate,AssetCOCDate,AssetConnections,AssetDescription,AssetDimensions,AssetLiftDate,AssetLocation,AssetMajorTestDate,AssetPressureRating,AssetSerialNumber,AssetWeight,COC,ProjectID")] Asset asset)
        {
            if (ModelState.IsValid)
            {
                _context.Add(asset);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["ProjectID"] = new SelectList(_context.Projects, "ProjectID", "ProjectClient", asset.ProjectID);
            return(View(asset));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Id,Name,SyllabusId")] Subject subject)
        {
            if (ModelState.IsValid)
            {
                _context.Add(subject);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["SyllabusId"] = new SelectList(_context.Syllabuss, "Id", "Id", subject.SyllabusId);
            return(View(subject));
        }
コード例 #4
0
ファイル: ProgramsController.cs プロジェクト: evge29/Project
        public async Task <IActionResult> Create([Bind("ProgramID,Name,Payment,Duration,CoachId")] Programs programs)
        {
            if (ModelState.IsValid)
            {
                _context.Add(programs);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CoachId"] = new SelectList(_context.Coaches, "CoachId", "FullName", programs.CoachId);
            return(View(programs));
        }
コード例 #5
0
 static void Main(string[] args)
 {
     using (ProjectContext db = new ProjectContext())
     {
         Project p = new Project()
         {
             ProjectName = "vhtgh"
         };
         db.Add(p);
         db.SaveChanges();
     }
 }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("TourId,TourTitle,ToursStartAt,ToursEndAt,CategoryId")] Tour tour)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tour);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryName"] = new SelectList(_context.Category, "CategoryName", "CategoryName", tour.CategoryId);
            return(View(tour));
        }
コード例 #7
0
        public async Task <IActionResult> Create([Bind("IndustryId,IndustryName,IndustryDescription,SectorId")] Industry industry)
        {
            if (ModelState.IsValid)
            {
                _context.Add(industry);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["SectorId"] = new SelectList(_context.Sectors, "SectorId", "SectorId", industry.SectorId);
            return(View(industry));
        }
コード例 #8
0
        public async Task <IActionResult> Create([Bind("ContractorId,FirstName,LastName,CompanyId,Email,Password")] Contractor contractor)
        {
            if (ModelState.IsValid)
            {
                _context.Add(contractor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CompanyId"] = new SelectList(_context.Company, "CompanyId", "CompanyId", contractor.CompanyId);
            return(View(contractor));
        }
コード例 #9
0
        public async Task <IActionResult> Create([Bind("ID,IncidentID,Corrections")] Report report)
        {
            if (ModelState.IsValid)
            {
                _context.Add(report);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IncidentID"] = new SelectList(_context.Incidents, "ID", "ID", report.IncidentID);
            return(View(report));
        }
コード例 #10
0
        public async Task <IActionResult> Create([Bind("ID,TypeID,Name,Description")] Incident incident)
        {
            if (ModelState.IsValid)
            {
                _context.Add(incident);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TypeID"] = new SelectList(_context.Types, "ID", "ID", incident.TypeID);
            return(View(incident));
        }
コード例 #11
0
        public async Task <IActionResult> Create([Bind("EnrollmentID,ProgramID,ClientID,InitialWeight,FinalWeight,FinishDate")] Enrollment enrollment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(enrollment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ClientID"]  = new SelectList(_context.Clients, "ID", "ClientID", enrollment.ClientId);
            ViewData["ProgramID"] = new SelectList(_context.Programs, "ProgramID", "Duration", enrollment.ProgramId);
            return(View(enrollment));
        }
コード例 #12
0
        public async Task <IActionResult> Create([Bind("Id,Name,DepartmentId")] Teacher teacher)
        {
            if (ModelState.IsValid)
            {
                _context.Add(teacher);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            // Console.WriteLine ('adf');
            ViewData["DepartmentId"] = new SelectList(_context.Departments, "Id", "Name", teacher.DepartmentId);
            return(View(teacher));
        }
コード例 #13
0
 public ActionResult Create(Student student)
 {
     try
     {
         projectContext.Add(student);
         projectContext.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
コード例 #14
0
        public async Task <IActionResult> Create([Bind("Id,Title,Credits,Semester,Programme,EducationLevel,FirstTeacherID,SecondTeacherID")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FirstTeacherID"]  = new SelectList(_context.Teacher, "Id", "FullName", course.FirstTeacherID);
            ViewData["SecondTeacherID"] = new SelectList(_context.Teacher, "Id", "FullName", course.SecondTeacherID);
            return(View(course));
        }
コード例 #15
0
        public async Task <IActionResult> Create([Bind("ContractId,P1CharRate,P1PayRate,P1StartDate,P1EndtDate,P2CharRate,P2PayRate,P2StartDate,P2EndtDate,P3CharRate,P3PayRate,P3StartDate,P3EndtDate,P4CharRate,P4PayRate,P4StartDate,P4EndtDate,Renewal,ActiveContract,ContractorId,CompanyId")] Contract contract)
        {
            if (ModelState.IsValid)
            {
                _context.Add(contract);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CompanyId"]    = new SelectList(_context.Company, "CompanyId", "CompanyId", contract.CompanyId);
            ViewData["ContractorId"] = new SelectList(_context.Contractor, "ContractorId", "ContractorId", contract.ContractorId);
            return(View(contract));
        }
コード例 #16
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,PartyId,StateId")] Candidates candidates)
        {
            if (ModelState.IsValid)
            {
                _context.Add(candidates);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PartyId"] = new SelectList(_context.Party, "Id", "Name", candidates.PartyId);
            ViewData["StateId"] = new SelectList(_context.State, "Id", "Id", candidates.StateId);
            return(View(candidates));
        }
コード例 #17
0
        public async Task <IActionResult> Create([Bind("id,StudentId,ScoreId")] StudentScore studentScore)
        {
            if (ModelState.IsValid)
            {
                _context.Add(studentScore);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ScoreId"]   = new SelectList(_context.Scores, "Id", "Id", studentScore.ScoreId);
            ViewData["StudentId"] = new SelectList(_context.Students, "Id", "Email", studentScore.StudentId);
            return(View(studentScore));
        }
コード例 #18
0
        public async Task <IActionResult> Create(Product product)
        {
            ViewBag.CategoryId = new SelectList(_context.Categories.OrderBy(x => x.Sorting), "Id", "Name");

            if (ModelState.IsValid)                                                                  //Eğer kendime model aldığım Product classındaki Propertyler istenilen şartlara sahipse
            {
                product.Slug = product.Name.ToLower().Replace(" ", "-");                             //product Slug'ına Name'ine verilen değeri küçük harflere çevir ve içinde boşuk varsa boşluk kadar tire(-) ekle ve Slug'ına o değeri ver diyorum.

                var slug = await _context.Products.FirstOrDefaultAsync(x => x.Slug == product.Slug); //daha sonra yeni olusturulan Slug'la aynı Slug değerine sahip bir Slug varmı yok mu diye bak ve bunun adına slug diyorum.

                if (slug != null)                                                                    //Eğer bu slug boş değilse yani aynı değerde bir slug varsa
                {
                    ModelState.AddModelError("", "The product already exists..!");                   //zaten böyle bir product mevcut diye mesaj iletecek.Biz burada Slug'la kontrolleri gerçekleştiriyoruz Slug'ları Id gibi uniq yani tek gibi kullandıgımız için kontrolleri onun üzerinden gerçekleştiriyoruz.
                    return(View(product));                                                           //Mesajla birlikte olusturulmaya çalışılan product ekranda görünsün
                }

                string imageName = "noimage.png"; //İmageName'ine Default bir değer atadım.
                if (product.ImageUpload != null)  //product'ın ImageUpload'ı null yani boş değilse
                {
                    //Dir birşeyin yolunu belirtir."-Dir" bir dizin yapısıdır.

                    string uploadDir = Path.Combine(_webHostEnvironment.WebRootPath, "media/products"); //Burada diyoumki _webHostEnvironment'in WebRootPath'unu al ve media içindeki products'ın içine göm diyoruz.
                                                                                                        //Not bu aşamadan sonra wwwroot içerinde media ve media klasörünün içerisine products klasörü açıyoruz.
                                                                                                        //Bu klasör sayesinde eklenen her fotograf aynı zamanda burada öbeklenecek.
                                                                                                        //_webHostEnvironment.WebRootPath bu sayede kendi fotograflarımıda bir yol gösterebiliyorum.Gidin burada kayıt olun diyoruz.

                    //Burada her bir resim yükleme işlemi esnasında her product'ın İmageName'ini Uniq yapıyorum ki çakışmalar olmasın
                    imageName = Guid.NewGuid().ToString() + "_" + product.ImageUpload.FileName; //Guid olarak bir veri üret bunu string'e çevir ve bu veriyi yeni olusturulmaya çalışılan product'ın isminede araya tire ekleyerek db'de Imageatamasını yap diyoruz bunun yeni ismide imageName olarak atıyoruz

                    string filePath = Path.Combine(uploadDir, imageName);                       //uploadDir uzantısı ile imageName'ini birleştir yani Combine et ve bunu string tipte olan filePath'e ata diyoruz.

                    FileStream fs = new FileStream(filePath, FileMode.Create);                  //?
                    await product.ImageUpload.CopyToAsync(fs);                                  //?

                    fs.Close();                                                                 //?

                    //FileMode= İşletim sisteminin bir dosyayı nasıl açması gerektiğini belirtir.
                    //FileStream:dosyalar ile akış işlemleri yapmamızı sağlar.
                    //Close: Akış kapatılır.
                }

                product.Image = imageName;//Artık olusturmak istediğim product'ın Image'ine olusturmus oldugu imageName'i ekle

                _context.Add(product);
                await _context.SaveChangesAsync();

                TempData["Success"] = "The product has been added..!";
            }

            return(View(product));
        }
コード例 #19
0
ファイル: ProjectRepository.cs プロジェクト: lchlfe/User.API
 public ProjectEntity Add(ProjectEntity project)
 {
     if (project.IsTransient())
     {
         return(_context.Add(project).Entity);
         //var result = _context.Add(project).Entity;
         //_context.SaveChanges();
         //return result;
     }
     else
     {
         return(project);
     }
 }
コード例 #20
0
        public async Task <IActionResult> Create([Bind("ID,IncidentID,AuditorID,AuthorID")] Main main)
        {
            if (ModelState.IsValid)
            {
                _context.Add(main);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuditorID"]  = new SelectList(_context.Auditors, "ID", "ID", main.AuditorID);
            ViewData["AuthorID"]   = new SelectList(_context.Authors, "ID", "ID", main.AuthorID);
            ViewData["IncidentID"] = new SelectList(_context.Incidents, "ID", "ID", main.IncidentID);
            return(View(main));
        }
コード例 #21
0
        public async Task <IActionResult> PurchaseProduct([Bind("Count,PurchaseDate,ProductId,id,BranchId, UserId")] Purchase purchase)
        {
            if (HttpContext.Session.GetString("isLogin") != "true")
            {
                return(Unauthorized());
            }

            // case the user put new image to update
            if (ModelState.IsValid)
            {
                try
                {
                    if (!_context.Products.Any(val => val.Id == purchase.ProductId) ||
                        !_context.Branches.Any(val => val.Id == purchase.BranchId) ||
                        !_context.Users.Any(val => val.Id == purchase.UserId))
                    {
                        return(NotFound());
                    }
                    _context.Add(purchase);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(purchase.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            PopulateBranchesDropDownList(purchase.BranchId);
            return(View(@"Views\Products\Index.cshtml"));
        }
コード例 #22
0
        public async Task <IActionResult> Create(ProjectsCreation projectVM)
        {
            if ((projectVM.Project.StartDate <= projectVM.Project.EndDate) && (projectVM.Project.EndDate > DateTime.UtcNow.Date))
            {
                projectVM.Project.CreatorId = GetUserID();
                projectVM.Project.Fundsrecv = 0;
                projectVM.Project.Packages  = new List <Packages>
                {
                    projectVM.Packages
                };

                var path        = $"/uploads/{projectVM.Photo.FileName}";
                var pathForHost = _hostingEnvironment.WebRootPath + $"/uploads/{projectVM.Photo.FileName}";

                using (var stream = new FileStream(pathForHost, FileMode.Create))
                {
                    await projectVM.Photo.CopyToAsync(stream);
                }

                var myphoto = new Photos()
                {
                    Filename = path
                };

                projectVM.Project.Photos = new List <Photos>
                {
                    myphoto
                };

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

                    return(RedirectToAction(nameof(Index)));
                }
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Name", projectVM.Project.CategoryId);
            ViewData["Wrong Date"] = "Check your Start Date and your End Date";

            return(View(projectVM));

            //_context.Add(projects);
            //await _context.SaveChangesAsync();
            //return Json(new {
            //    title = projects.Title,
            //    redirect = Url.Action("Details", "Project", new { id = projects.Id})
            //});
        }
コード例 #23
0
        public async Task <IActionResult> Create([Bind("Id,DonationUpperlim,Reward,ProjectId")] Packages packages, long project_id)
        {
            if (ModelState.IsValid)
            {
                _context.Add(packages);
                await _context.SaveChangesAsync();

                //we need this to navigate back to the project we were browsing...
                project_id = packages.ProjectId;

                return(RedirectToAction(nameof(Index), new { project_id }));
            }
            ViewData["ProjectId"] = new SelectList(_context.Projects, "Id", "Title", packages.ProjectId);
            return(View(packages));
        }
コード例 #24
0
        public IActionResult Post([FromBody] User u)
        {
            //als u null is return null statement. anders add u aan databse
            if (u == null)
            {
                return(NoContent());
            }
            else
            {
                _context.Add(u);
                _context.SaveChanges();

                return(Ok());
            }
        }
コード例 #25
0
        public async Task <IActionResult> Create([Bind("Name,Price,Src,Alt,EngineId,ModelId,FuelId,TransmissionId,Id,CreatedAt,UpdatedAt")] Car car)
        {
            if (ModelState.IsValid)
            {
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EngineId"]       = new SelectList(_context.Engines, "Id", "Name", car.EngineId);
            ViewData["FuelId"]         = new SelectList(_context.Fuels, "Id", "Type", car.FuelId);
            ViewData["ModelId"]        = new SelectList(_context.Models, "Id", "Name", car.ModelId);
            ViewData["TransmissionId"] = new SelectList(_context.Transmissions, "Id", "Type", car.TransmissionId);
            return(View(car));
        }
コード例 #26
0
ファイル: SuppliersController.cs プロジェクト: ronavraham/grd
        public async Task <IActionResult> Create([Bind("Id,Name")] Supplier supplier)
        {
            if (!IsAuthorized())
            {
                return(Unauthorized());
            }
            if (ModelState.IsValid)
            {
                _context.Add(supplier);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(supplier));
        }
コード例 #27
0
        public async Task <IActionResult> Create([Bind("Lat,Long,Name,City,Address,Telephone,IsSaturday,Id")] Branch branch)
        {
            if (!IsAuthorized())
            {
                return(Unauthorized());
            }
            if (ModelState.IsValid)
            {
                _context.Add(branch);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(BadRequest());
        }
コード例 #28
0
        public async Task <IActionResult> Create([Bind("PlayerId,FifaPlayerId,Name,Picture,Position,Rating,CardType,GamesPlayed,Goals,Assists,MatchRating,OwnGoals,ShotsOnTarget,ShotsOffTarget,PassesCompletedS,PassesCompletedM,PassesCompletedL,PassesFailedS,PassesFailedM,PassesFailedL,CrossesCompleted,CrossesFailed,KeyPasses,DribblesCompleted,DribblesAttempted,KeyDribbles,OneOnOneDribbles,Fouled,TacklesWon,TacklesAttempted,Fouls,PensConceded,Interceptions,OutOfPosition,Blocks,Clearances,HeadersWon,HeadersLost,GoalsConceded,ShotsCaught,ShotsParried,CrossesCaught,BallsStripped,YellowCards,RedCards,Injuried,ManOfTheMatch")] Player player)
        {
            Team team = new Team();

            if (ModelState.IsValid)
            {
                _context.Add(player);
                var inc = player.PlayerId;
                team.UserId    = _userManager.GetUserId(User);
                team.PlayersId = inc;
                _context.Team.Add(team);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(player));
        }
コード例 #29
0
        public async Task CreateRequestForCommandAsync <T>(Guid id)
        {
            var exists = await ExistAsync(id);

            var request = exists ?
                          throw new ProjectDomainException($"Request with {id} already exists") :
                                new ClientRequest()
                                {
                                    Id   = id,
                                    Name = typeof(T).Name,
                                    Time = DateTime.UtcNow
                                };

            _context.Add(request);

            await _context.SaveChangesAsync();
        }
コード例 #30
0
        public IActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                PasswordHasher <User> Hasher = new PasswordHasher <User>();
                user.password         = Hasher.HashPassword(user, user.password);
                user.confirm_password = Hasher.HashPassword(user, user.confirm_password);

                _context.Add(user);
                _context.SaveChanges();

                return(View("Success"));
            }
            else
            {
                return(View("Index"));
            }
        }