public async Task <IActionResult> Edit(int id, [Bind("IdEducationalInstitution,NameEducationalInstitution,IdTown")] EducationalInstitution educationalInstitution) { if (id != educationalInstitution.IdEducationalInstitution) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(educationalInstitution); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EducationalInstitutionExists(educationalInstitution.IdEducationalInstitution)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IdTown"] = new SelectList(_context.City, "IdTown", "NameCity", educationalInstitution.IdTown); return(View(educationalInstitution)); }
public void Create(EducationalInstitution educationalInstitution) { if (!IsNameAvailable(educationalInstitution.Name, educationalInstitution.Id)) { throw new ApplicationException("Un Establecimiento Educativo con el mismo nombre ya ha sido creado"); } educationalInstitution.CreatedDate = _clock.Now; Uow.EducationalInstitutions.Add(educationalInstitution); Uow.Commit(); }
public async Task <IActionResult> Create([Bind("IdEducationalInstitution,NameEducationalInstitution,IdTown")] EducationalInstitution educationalInstitution) { if (ModelState.IsValid) { _context.Add(educationalInstitution); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IdTown"] = new SelectList(_context.City, "IdTown", "NameCity", educationalInstitution.IdTown); return(View(educationalInstitution)); }
public void Edit(EducationalInstitution educationalInstitution) { var currentEducationalInstitution = this.GetById(educationalInstitution.Id); currentEducationalInstitution.ModifiedDate = _clock.Now; currentEducationalInstitution.Name = educationalInstitution.Name; currentEducationalInstitution.TownId = educationalInstitution.TownId; currentEducationalInstitution.Location = educationalInstitution.Location; Uow.EducationalInstitutions.Edit(currentEducationalInstitution); Uow.Commit(); }
public int AddEducationalInstitution(EducationalInstitution data) { var checkNumber = _context.EducationalInstitution.Any(x => x.title == data.title); if (checkNumber) { return(-1); } var res = _context.EducationalInstitution.Add(data); _context.SaveChanges(); return(res.Entity.id); }
public IActionResult PutEducationalInstitution(int id, [FromBody] EducationalInstitution data) { try { var res = _repository.UpdateEducationalInstitution(id, data); if (!res) { return(Conflict(409)); } return(Ok(res)); } catch (Exception error) { return(BadRequest(error)); } }
public IActionResult PostEducationalInstitution(EducationalInstitution data) { try { var res = _repository.AddEducationalInstitution(data); if (res == -1) { return(Conflict(409)); } return(Ok(res)); } catch (Exception error) { return(BadRequest(error)); } }
public bool UpdateEducationalInstitution(int id, EducationalInstitution data) { var res = _context.EducationalInstitution.FirstOrDefault(x => x.id == id); if (res == null) { return(false); } var checkNumber = _context.EducationalInstitution.Where(x => x.id != id).Any(x => x.title == data.title); if (checkNumber) { return(false); } res.title = data.title; _context.SaveChanges(); return(true); }
private async Task <long> AddUniversity() { var institution = new EducationalInstitution { Name = "Томский Политехнический Университет", SiteUrl = "http://tpu.ru/", Acronym = "НИ ТПУ", Description = "Политех", AreaId = await _context.Areas.Select(x => x.Id).FirstAsync() }; _context.EducationalInstitutions.Add(institution); await _context.SaveChangesAsync(); var @event = new EducationalInstitutionsChanged { Created = new[] { Mapper.Map <DtoEducationalInstitution>(institution) } }; _eventBus.Publish(@event); return(institution.Id); }
public ActionResult Create(EducationalnstituteViewModels EduVM, HttpPostedFileBase file) { EducationalInstitution EduModel = new EducationalInstitution(); //TODO: Add insert logic here try { if (ModelState.IsValid) { string path = ""; if (file != null) { EduModel.InstituionImage = file.FileName; path = Server.MapPath("~\\Content\\images\\Education"); file.SaveAs(path + file.FileName); System.IO.DirectoryInfo di = new DirectoryInfo(path); //foreach (FileInfo files in di.GetFiles()) //{ // if (files.Name != acc.AccomodationImage) // { // files.Delete(); // } //} } else { } EduModel.InstitutionName = EduVM.InstitutionName; EduModel.Location = EduVM.Location; EduModel.Address = EduVM.Address; EduModel.Email = ""; EduModel.Phone = 123456; EduModel.Link = EduVM.Link; EduModel.Description = EduVM.Description; EduModel.CreatedDate = DateTime.Now; EduModel.ModifiedDate = DateTime.Now; EduModel.IsDelete = false; //using (db = new kiwilandDbEntities()) //{ // using (DbContextTransaction trans = db.Database.BeginTransaction()) // { db.EducationalInstitutions.Add(EduModel); int status = db.SaveChanges(); // } //} } return(RedirectToAction("Index")); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } }
/// <summary> /// Инициализация таблицы "Образовательные организации" /// </summary> /// <param name="serviceProvider"></param> /// <param name="configuration"></param> /// <returns></returns> public static async Task CreateEducationalInstitutions(IServiceProvider serviceProvider, IConfiguration configuration) { using (var serviceScope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope()) { AppIdentityDBContext context = serviceScope.ServiceProvider.GetService <AppIdentityDBContext>(); #region Инициализация таблицы "Образовательные организации" if (!await context.EducationalInstitutions.AnyAsync()) { var row01 = new EducationalInstitution { EducationalInstitutionId = 1, EducationalInstitutionName = "МБОУ гимназия г.Зернограда", EducationalInstitutionTypeId = (int)EducationalInstitutionTypeEnum.ObsheobrazovatelnayaOrganizaciya, Location = new Location { Address = new Address { Country = "Россия", PostCode = "347740", PopulatedLocalityId = 1, Region = "Ростовская область", Settlement = "г. Зерноград", Street = "ул. Советская", HouseNumber = "42/11" }, GpsCoordinate = new GpsCoordinate { Latitude = 46.851765m, Longitude = 40.313441m } } }; var row02 = new EducationalInstitution { EducationalInstitutionId = 2, EducationalInstitutionName = "МБОУ СОШ УИОП г.Зернограда", EducationalInstitutionTypeId = (int)EducationalInstitutionTypeEnum.ObsheobrazovatelnayaOrganizaciya, Location = new Location { Address = new Address { Country = "Россия", PostCode = "347740", PopulatedLocalityId = 1, Region = "Ростовская область", Settlement = "г. Зерноград", Street = "ул. Ленина", HouseNumber = "42" }, GpsCoordinate = new GpsCoordinate { Latitude = 46.853572m, Longitude = 40.320881m } } }; var row03 = new EducationalInstitution { EducationalInstitutionId = 3, EducationalInstitutionName = "Азово-Черноморский инженерный институт ФГБОУ ВО Донской ГАУ", EducationalInstitutionTypeId = (int)EducationalInstitutionTypeEnum.ObrazovatelnayaOrganizaciyaVisshegoObrazovaniya, Location = new Location { Address = new Address { Country = "Россия", PostCode = "347740", PopulatedLocalityId = 1, Region = "Ростовская область", Settlement = "г. Зерноград", Street = "ул. Ленина", HouseNumber = "21" }, GpsCoordinate = new GpsCoordinate { Latitude = 46.847864m, Longitude = 40.309868m } } }; await context.EducationalInstitutions.AddRangeAsync( row01, row02, row03 ); await context.SaveChangesAsync(); } #endregion } }