private void InsertOrUpdateLabel(Label @new, Label old) { var entity = _dbContext.Labels .Where(it => it.SiteName == @new.Site.FullName && it.Name == @new.Name && it.Category == (@new.Category ?? "")) .FirstOrDefault(); if (entity != null) { entity.Value = @new.Value; } else { if (!string.IsNullOrEmpty(@new.Category)) { AddCategory(@new.Site, @new.Category); } entity = new LabelEntity(@new.Site.FullName, @new.Name, @new.Value, @new.Category); entity.UUID = @new.UUID; entity.UtcCreationDate = @new.UtcCreationDate; _dbContext.Labels.Add(entity); } entity.LastestEditor = @new.LastestEditor; entity.UtcLastestModificationDate = @new.UtcLastestModificationDate; _dbContext.SaveChanges(); }
public ActionResult Create([Bind(Include = "ID,Data,Caption,Width,Height,Filename,ContentType")] SitePicture sitePicture, HttpPostedFileBase file) { sitePicture.ContentType = file.ContentType; sitePicture.Filename = file.FileName; if (!ModelState.IsValidField("Data")) { ModelState["Data"].Errors.Clear(); byte[] img = new byte[file.ContentLength]; int byteCount = file.InputStream.Read(img, 0, img.Length); sitePicture.Data = img; if (!TryValidateModel(sitePicture)) { return(View(sitePicture)); } } if (ModelState.IsValid) { db.SitePictures.Add(sitePicture); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(sitePicture)); }
public void Remove(UrlRedirect item) { var obj = _dbContext.UrlRedirects.FirstOrDefault(it => it.UUID.Equals(item.UUID, StringComparison.OrdinalIgnoreCase)); if (null != obj) { _dbContext.UrlRedirects.Remove(obj); _dbContext.SaveChanges(); } }
public ActionResult Create([Bind(Include = "Id,Codigo,Nome,Descricao,Cor")] Area area) { if (ModelState.IsValid) { db.Areas.Add(area); db.SaveChanges(); ViewBag.Mensagem = "Dados salvos com sucesso"; } return(View(area)); }
public ActionResult Create([Bind(Include = "Id,Titulo,Resumo,Texto,Cadastro,Publicado")] Noticia noticia) { if (ModelState.IsValid) { db.Noticias.Add(noticia); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(noticia)); }
public ActionResult Create([Bind(Include = "Id,Employer,Title,StartDate,EndDate,Description")] WorkHistory workHistory) { if (ModelState.IsValid) { db.Resumes.FirstOrDefault().WorkHistoryList.Add(workHistory); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(workHistory)); }
public ActionResult Create([Bind(Include = "Id,Nome,Modulo_Id")] Disciplina disciplina) { if (ModelState.IsValid) { db.Disciplinas.Add(disciplina); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Modulo_Id = new SelectList(db.Moduloes, "Id", "Nome", disciplina.Modulo_Id); return(View(disciplina)); }
public ActionResult Create([Bind(Include = "Id,Curriculo,PessoaId")] Professor professor) { if (ModelState.IsValid) { db.Professores.Add(professor); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PessoaId = new SelectList(db.Pessoas, "Id", "Nome", professor.PessoaId); return(View(professor)); }
public void Remove(ABTest.ABPageTestResult item) { ((IPersistable)item).OnSaving(); var dummy = _dbContext.ABPageTestResults.FirstOrDefault(it => it.UUID.Equals(item.UUID, StringComparison.OrdinalIgnoreCase) && it.SiteName.Equals(item.Site.FullName, StringComparison.OrdinalIgnoreCase)); if (null != dummy) { _dbContext.ABPageTestResults.Remove(dummy); _dbContext.SaveChanges(); } ((IPersistable)item).OnSaved(); }
public ActionResult Create([Bind(Include = "Id,Valor,Disciplina_Id,Aluno_Id")] Nota nota) { if (ModelState.IsValid) { db.Notas.Add(nota); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Aluno_Id = new SelectList(db.Alunos, "ID", "Nome", nota.Aluno_Id); ViewBag.Disciplina_Id = new SelectList(db.Disciplinas, "Id", "Nome", nota.Disciplina_Id); return(View(nota)); }
public ActionResult Create([Bind(Include = "ID,IDAluno,IDCurso,DataMatricula,Situacao,DataPago,IdTransacao")] Matricula matricula) { if (ModelState.IsValid) { db.Matriculas.Add(matricula); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IDAluno = new SelectList(db.Alunos, "ID", "Nome", matricula.IDAluno); ViewBag.IDCurso = new SelectList(db.Cursos, "ID", "Titulo", matricula.IDCurso); return(View(matricula)); }
public ActionResult Create([Bind(Include = "ID,Nome,NomeGenitora,DataNascimento,Email,Endereco,Bairro,CEP,UF,Cidade,Telefone,CPF,RG,Observacao,Senha,DataCadastro")] Aluno aluno) { if (ModelState.IsValid) { db.Alunos.Add(aluno); db.SaveChanges(); ViewBag.Mensagem = "Dados salvos com sucesso"; } else { ViewBag.Mensagem = "Não foi possível salvar os dados."; } return(View(aluno)); }
public ActionResult Create([Bind(Include = "Id,Nome,Email,Endereco,Bairro,CEP,UF,Cidade,Celular,CPF,RG")] Pessoa pessoa) { if (ModelState.IsValid) { db.Pessoas.Add(pessoa); db.SaveChanges(); ViewBag.Mensagem = "Dados salvos com sucesso"; } else { ViewBag.Mensagem = "Não foi possível salvar os dados."; } return(View(pessoa)); }
// GET: RetornoPagamento/Edit/5 public ActionResult Retorno(string notificationType, string notificationCode) { AccountCredentials credentials = PagSeguroConfiguration.Credentials(true); if (notificationType == "transaction") { // obtendo o objeto transaction a partir do código de notificação Transaction transaction = NotificationService.CheckTransaction( credentials, notificationCode ); int status = transaction.TransactionStatus; if (status == 3) // paga { string referencia = transaction.Reference; DateTime data = transaction.LastEventDate; int id = Int32.Parse(referencia.Substring(3)); Matricula mat = db.Matriculas.Find(id); mat.DataPago = data; mat.Situacao = "P"; // pago db.Entry(mat).State = EntityState.Modified; db.SaveChanges(); } } ViewBag.Mensagem = "Processada."; return(View()); }
private void UpdateOrAdd(Site @new, Site old) { ((IPersistable)@new).OnSaving(); var dummy = _dbContext.SiteSettings.FirstOrDefault(it => it.FullName.Equals(old.FullName, StringComparison.OrdinalIgnoreCase)); if (null != dummy) { @new.ToSiteSettingEntity(dummy); } else { dummy = @new.ToSiteSettingEntity <SiteEntity>(); _dbContext.SiteSettings.Add(dummy); } _dbContext.SaveChanges(); ((IPersistable)@new).OnSaved(); }
public ActionResult Create([Bind(Include = "Id,Nome,Curso_Id")] Modulo modulo) { if (ModelState.IsValid) { db.Moduloes.Add(modulo); db.SaveChanges(); ViewBag.Mensagem = "Dados salvos com sucesso"; } else { ViewBag.Mensagem = "Não foi possível salvar os dados."; } ViewBag.curso = db.Cursos.Find(modulo.Curso_Id); return(View(modulo)); }
private void InsertOrUpdate(Models.HtmlBlock @new, Models.HtmlBlock old) { var entity = _dbContext.HtmlBlocks .Where(it => it.SiteName == @new.Site.FullName && it.Name == @new.Name) .FirstOrDefault(); if (entity != null) { entity.Body = @new.Body; } else { entity = new HtmlBlockEntity(@new); _dbContext.HtmlBlocks.Add(entity); } _dbContext.SaveChanges(); }
private void UpdateOrAdd(ABPageSetting item, ABPageSetting oldItem) { ((IPersistable)item).OnSaving(); var dummy = _dbContext.ABPageSettings.FirstOrDefault(it => it.UUID.Equals(oldItem.UUID, StringComparison.OrdinalIgnoreCase) && it.SiteName.Equals(oldItem.Site.FullName, StringComparison.OrdinalIgnoreCase)); if (null != dummy) { item.ToABPageSettingEntity <ABPageSettingEntity>(dummy); } else { dummy = item.ToABPageSettingEntity <ABPageSettingEntity>(); _dbContext.ABPageSettings.Add(dummy); } _dbContext.SaveChanges(); ((IPersistable)item).OnSaved(); }
private void InsertOrUpdate(Models.User @new, Models.User old) { var entity = _dbContext.SiteUsers .Where(it => it.SiteName == @new.Site.FullName && it.UserName == @new.UserName) .FirstOrDefault(); if (entity != null) { entity = SiteUserHelper.ToEntity(@new, entity); } else { entity = entity = SiteUserHelper.ToEntity(@new, entity); _dbContext.SiteUsers.Add(entity); } _dbContext.SaveChanges(); }
public ActionResult Create([Bind(Include = "ID,Codigo,Capa,Titulo,Descricao,Ementa,CargaHoraria,Vagas,DataInicio,DataConclusao,Horario,InicioInscricao,FimInscricao,Local,Investimento,Valor, Area_Id, Professor_Id, Coordenador_Id")] Curso curso) { if (ModelState.IsValid) { curso.Capa = curso.Capa == null ? "" : curso.Capa; db.Cursos.Add(curso); db.SaveChanges(); ViewBag.Mensagem = "Dados salvos com sucesso"; } else { ViewBag.Mensagem = "Não foi possível salvar os dados."; } ViewBag.Coordenador_Id = new SelectList(db.Coordenadores.ToList(), "ID", "Nome"); ViewBag.Professor_Id = new SelectList(db.Professores.ToList(), "ID", "Nome"); ViewBag.Area_Id = new SelectList(db.Areas.ToList(), "ID", "Nome"); return(View(curso)); }
private void InsertOrUpdateLabel(Element @new, Element old) { var entity = _dbContext.Labels .Where(it => it.SiteName == SiteName && it.Name == @new.Name && it.Category == (@new.Category ?? "")) .FirstOrDefault(); if (entity != null) { entity.Value = @new.Value; } else { if (!string.IsNullOrEmpty(@new.Category)) { AddCategory(@new.Category, @new.Culture); } entity = new LabelEntity(SiteName, @new); _dbContext.Labels.Add(entity); } _dbContext.SaveChanges(); }
public ActionResult Edit([Bind(Include = "Id,Curriculo,PessoaId")] Coordenador coordenador) { Coordenador coord = db.Coordenadores.Find(coordenador.Id); if (coord == null) { db.Coordenadores.Add(coordenador); db.SaveChanges(); } else { if (ModelState.IsValid) { coord.Curriculo = coordenador.Curriculo; db.Entry(coord).State = EntityState.Modified; db.Entry(coord).Property("PessoaId").IsModified = false; db.SaveChanges(); } } return(View(coordenador)); }
public void Remove(ABTest.ABRuleSetting item) { ((IPersistable)item).OnSaving(); var dummy = _dbContext.ABRuleSettings.Where(it => it.UUID.Equals(item.UUID, StringComparison.OrdinalIgnoreCase)); if (null != item.Site) { dummy = dummy.Where(it => it.SiteName.Equals(item.Site.FullName, StringComparison.OrdinalIgnoreCase)); } else { dummy = dummy.Where(it => String.IsNullOrEmpty(it.SiteName)); } var temp = dummy.FirstOrDefault(); if (null != temp) { _dbContext.ABRuleSettings.Remove(temp); _dbContext.SaveChanges(); } ((IPersistable)item).OnSaved(); }
public ActionResult Index(QuoteInformation quote) { //return View(db.QuoteInformations.ToList()); if (ModelState.IsValid) { db.QuoteInformations.Add(quote); db.SaveChanges(); return(RedirectToAction("ThankYou", new { fullName = quote.FullName })); } else { return(View(quote)); } }
public void SaveAsDraft(Models.Page page) { var entity = _dbContext.PageDrafts .Where(it => it.SiteName == page.Site.FullName && it.FullName == page.FullName) .FirstOrDefault(); if (entity != null) { PageEntityHelper.ToPageEntity(page, entity); } else { _dbContext.PageDrafts.Add(PageEntityHelper.ToPageEntity <PageDraftEntity>(page)); } _dbContext.SaveChanges(); }
public IActionResult Upload(List <IFormFile> formFiles) { if (!HttpContext.Session.Keys.Contains <string>("Authenticated")) { return(View("Unauthorized")); } foreach (var file in Request.Form.Files) { var path = ""; int index = file.FileName.IndexOf('.') + 1; string fileType = file.FileName.Substring(index).ToLower(); int categoryId = Int32.Parse(Request.Form["categoryId"]); FileCategories category = _context.FileCategories.First <FileCategories>(c => c.CategoryId == categoryId); path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Images", category.CategoryLabel, file.FileName); try { Images img = new Images(); img.ImgFileName = file.FileName; img.UploadedDate = DateTime.Now; img.IsPublished = 0; img.CategoryId = categoryId; using (var stream = new FileStream(path, FileMode.Create)) { file.CopyTo(stream); } _context.Images.Add(img); } catch (IOException) { return(View("../Shared/Error")); } _context.SaveChanges(); } return(RedirectToAction("Index")); }
public async Task <ActionResult> Confirmar() { if (Session["IdCurso"] == null) { return(View()); } var id = Session["IdCurso"]; Curso curso = await db.Cursos.FindAsync(id); if (curso == null) { return(HttpNotFound()); } if (curso.FimInscricao < DateTime.Now || curso.DataInicio.AddDays(7) < DateTime.Now) { ViewBag.Mensagem = "O período de inscrições já finalizou."; return(View()); } int totalInscritos = db.Matriculas.Where(m => !m.Situacao.Equals("C") && m.IDCurso == curso.ID).Count(); if (totalInscritos >= curso.Vagas) { ViewBag.Mensagem = "Não há mais vagas dispononíveis para o curso."; return(View()); } if (Session["Aluno"] == null) { return(RedirectToAction("NovoAluno", "Alunos")); } Aluno aluno = (Aluno)Session["Aluno"]; var transacao = db.Database.BeginTransaction(); try { Matricula matricula = new Matricula(); matricula.IDAluno = aluno.ID; matricula.IDCurso = curso.ID; matricula.DataMatricula = DateTime.Now; matricula.Situacao = "I"; //Inscrito db.Matriculas.Add(matricula); db.SaveChanges(); string plano = "Cursos = " + curso.Titulo; string nome = aluno.Nome; string telefone = aluno.Telefone; string uf = aluno.UF.ToUpper(); string cidade = aluno.Cidade; string bairro = aluno.Bairro; string cep = aluno.CEP; string endereco = aluno.Endereco; string cpf = aluno.CPF; PaymentRequest payment = new PaymentRequest(); payment.Items.Add(new Item("0001", plano, 1, curso.Valor)); payment.Sender = new Sender( nome, User.Identity.Name, new Phone( telefone.Substring(0, 2), telefone.Substring(2) ) ); payment.Shipping = new Shipping(); payment.Shipping.ShippingType = ShippingType.NotSpecified; payment.Shipping.Address = new Address( "BRA", uf, cidade, bairro, cep, endereco, "0", null ); payment.Currency = Currency.Brl; payment.Reference = "MAT" + matricula.ID.ToString(); SenderDocument senderDocument = senderDocument = new SenderDocument(Documents.GetDocumentByType("CPF"), cpf); payment.Sender.Documents.Add(senderDocument); payment.RedirectUri = new Uri("http://www.insesf.com/Inscricao/RetornoPagseguro"); payment.NotificationURL = "http://www.insesf.com/RetornoPagamento/Retorno"; AccountCredentials credentials = PagSeguroConfiguration.Credentials(sandbox); Uri paymentRedirectUri = payment.Register(credentials); string url = paymentRedirectUri.AbsoluteUri; transacao.Commit(); Session["IdCurso"] = null; Session["TituloCurso"] = null; return(Redirect(url)); } catch (PagSeguroServiceException e) { transacao.Rollback(); ViewBag.Mensagem = string.Format("Não foi possível processar a matrícula. Tente de novo mais tarde. {0}", e.ToString()); return(View()); } }