public async Task <IActionResult> Create([Bind("GrupId,Name,DirectId,isPranet")] Grup grup) { if (ModelState.IsValid) { if (grup.isPranet) { if (_context.Grups.FirstOrDefault(x => x.DirectId == grup.DirectId) == null) { _context.Add(grup); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } else { _context.Add(grup); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } ViewData["DirectionId"] = new SelectList(_context.Directions, "DirectionId", "Name"); return(View(grup)); }
public async Task <IActionResult> Create([Bind("DirectionId,Code,Name")] Direction direction) { if (ModelState.IsValid) { _context.Add(direction); await _context.SaveChangesAsync(); } var directions = _context.Directions.ToList(); ViewBag.direction = directions; return(View()); }
public async Task <IActionResult> Create([Bind("TeacherId,Name,Surname,Middilname,Position,AcademicDegree,DepartmentId")] Teacher teacher) { if (ModelState.IsValid) { _context.Add(teacher); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DepartmentName"] = new SelectList(_context.Departments, "DepartmentId", "Name"); return(View(teacher)); }
public async Task <IActionResult> Create([Bind("SubjectId,SubjectCode,Name,Lecture,Practical,Laboratory,Seminar,CourseWork,SubjectBlockTypeId,IndependentEducation,OneOne,OneTwo,TwoOneOneOne,OneTwo,TwoOne,TwoTwo,ThreeOne,ThreeTwe,FourOne,FourTwo,KOneOne,KOneTwo,KTwoOne,KTwoTwo,KThreeOne,KThreeTwe,KFourOne,KFourTwo")] Subject subject) { if (ModelState.IsValid) { _context.Add(subject); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["SubjectBlock"] = new SelectList(_context.SubjectBlockTypes, "Id", "Name"); return(View(subject)); }
public async Task <IActionResult> Create([Bind("StudentId,Name,Surname,Middilname,Course,Logn,Password,DirectionId")] Student student) { if (ModelState.IsValid) { _context.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DirectionName"] = new SelectList(_context.Directions, "DirectionId", "Name"); return(View(student)); }
public async Task <IActionResult> Create([Bind("FacultetID,Name")] Facultet facultet) { if (ModelState.IsValid) { _context.Add(facultet); await _context.SaveChangesAsync(); var _facultets = _context.Facultets.ToList(); ViewBag.facultets = _facultets; return(View()); } return(View(facultet)); }
public async Task <IActionResult> Create([Bind("Id,Name")] SubjectBlockType subjectBlockType) { var subjectBlocks = _context.SubjectBlockTypes.ToList(); ViewBag.subjectBlock = subjectBlocks; if (ModelState.IsValid) { _context.Add(subjectBlockType); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Create))); } return(View(subjectBlockType)); }
public async Task <IActionResult> Create([Bind("Id,TaskName,FileName,StartDate,EndDate")] DataModelEntity.Entity.Task task, [Bind("type")] string type, [Bind("bookUrl")] IFormFile bookUrl) { if (ModelState.IsValid) { task.FileName = Upload(bookUrl, task.FileName); task.GrupId = HarvestPlansController.CurrentGrupId; task.TaskType = type; task.SubjectId = subjectId; _context.Add(task); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(task)); }
public async Task <IActionResult> Create([Bind("DepartmentId,Name,FacultetId")] Department department) { if (ModelState.IsValid) { _context.Add(department); await _context.SaveChangesAsync(); var departments = _context.Departments.Include(x => x.GetFacultet).ToList(); ViewBag.departments = departments; ViewData["FacultetName"] = new SelectList(_context.Facultets, "FacultetID", "Name"); return(View()); } ViewData["FacultetName"] = new SelectList(_context.Facultets, "FacultetID", "Name"); return(View()); }
public async Task <IActionResult> SaveSubject() { if (Current != null) { Current.Grups = null; _context.Add(Current); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } else { return(NotFound()); } }
private void AddFieldRecords(EntityDbContext dc, Type fieldType) { FieldTypeAttribute fieldTypeAttribute = fieldType.BaseType.GetCustomAttributes(typeof(FieldTypeAttribute), false).First() as FieldTypeAttribute; String fieldTypeName = fieldTypeAttribute.GetFieldTypeName(); Fields.Where(x => x.FieldTypeName == fieldTypeName && x.Records != null) .ToList() .ForEach(field => { field.Records.ForEach(data => { var repository = data.ToObject(fieldType); dc.Add(repository); }); }); }
public async Task <IActionResult> Create([Bind("Name,Phone,Email,Id")] Supplier supplier) { if (User.Claims.Select(q => q.Value).FirstOrDefault() != null && HttpContext.Session.GetString("UserLoginEmail") == User.Claims.Select(q => q.Value).FirstOrDefault()) { supplier.RecordCreateTime = DateTime.Now; if (ModelState.IsValid) { _context.Add(supplier); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(supplier)); } return(RedirectToAction("Logout", "Login")); }
public async Task <IActionResult> Create([Bind("Information,ItemGivenTime,rlt_User_Id,rlt_Item_Id,Id,RecordCreateTime")] Allocation allocation) { if (User.Claims.Select(q => q.Value).FirstOrDefault() != null && HttpContext.Session.GetString("UserLoginEmail") == User.Claims.Select(q => q.Value).FirstOrDefault()) { if (ModelState.IsValid) { _context.Add(allocation); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["rlt_Item_Id"] = new SelectList(_context.Items, "Id", "Id", allocation.rlt_Item_Id); ViewData["rlt_User_Id"] = new SelectList(_context.Users, "Id", "Id", allocation.rlt_User_Id); return(View(allocation)); } return(RedirectToAction("Logout", "Login")); }
public async Task <IActionResult> AddUser([Bind("Name,Surname,rlt_Department_Id,Position,Password,Phone,Email,Id")] User user) { if (User.Claims.Select(q => q.Value).FirstOrDefault() != null && HttpContext.Session.GetString("UserLoginEmail") == User.Claims.Select(q => q.Value).FirstOrDefault()) { user.RecordCreateTime = DateTime.Now; if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(UserList))); } ViewData["rlt_Department_Id"] = new SelectList(_context.Departments, "Id", "Id", user.rlt_Department_Id); return(View(user)); } return(RedirectToAction("Logout", "Login")); }
public virtual bool InsertEntity(EntityDbContext dc, String entityName) { if (dc.Table(entityName).Any(x => (x as Entity).Id == Id)) { return(false); } dc.Add(this); LoadFieldsDefinition(dc); var types = TypeHelper.GetClassesWithInterface <IFieldRepository>(EntityDbContext.Assembles) .Where(x => x.Name.StartsWith(entityName) && x.Name.EndsWith("Field")).ToList(); types.ForEach(fieldType => { AddFieldRecords(dc, fieldType); }); return(true); }
public virtual void Test__Update(DummyModel fixtureDummyModel, DummyModel dto, DummyModel entity) { "Create fixture dummy model" .x(() => fixtureDummyModel = _fixture.Create <DummyModel>()); /*"Assign relationships" * .x(() => * { * fixtureDummyModel.Level1s.ForEach(x => * { * x.DummyModelRef = fixtureDummyModel; * x.DummyModelRefId = fixtureDummyModel.Id; * * x.L1P3.ForEach(y => * { * y.Level1Ref = x; * y.Level1RefId = x.Id; * * y.L2P3.ForEach(z => * { * z.Level2Ref = y; * z.Level2RefId = y.Id; * }); * }); * }); * });*/ "Add fixture dummy model to DbContext" .x(() => _dbContext.Add(fixtureDummyModel)); "SaveChanges of DbContext" .x(() => _dbContext.SaveChanges()); "Get entity from DbContext" .x(() => entity = _dbContext.DummyModels .Include(x => x.Level1s) .ThenInclude(x => x.L1P3) .ThenInclude(x => x.L2P3) .First()); "Get entity and convert it to DTO" .x(() => dto = entity.DeepClone()); "Update DTO".x(() => { dto.Level1s.Last().L1P3.First().L2P1 = "Hello world!"; dto.Level1s = dto.Level1s.Shuffle(); }); "Update entity" .x(() => UpdateDummyModel(entity, dto, _dbContext)); "SaveChanges of DbContext" .x(() => _dbContext.SaveChanges()); "Get entity from DbContext again" .x(() => entity = _dbContext.DummyModels .Include(x => x.Level1s) .ThenInclude(x => x.L1P3) .ThenInclude(x => x.L2P3) .First()); "Validate changes are applies to entity" .x(() => { entity.PrepareForJson(); dto.PrepareForJson(); var e = entity.ToJson(); var d = dto.ToJson(); Assert.Equal(entity, dto); }); }
public long persist(Game game) { _dbContext.Add(game); save(); return(game.id); }