public void UpdateStatus(int sid) { var obj = db.Slideshows.SingleOrDefault(s => s.ID == sid); obj.Status = !obj.Status; db.SubmitChanges(); }
public void Delete(int id) { var obj = db.Addresses.SingleOrDefault(a => a.ID == id); db.Addresses.DeleteOnSubmit(obj); db.SubmitChanges(); }
public ActionResult Create(RegisterModel model) { if (ModelState.IsValid) { var userId = Guid.NewGuid(); // Attempt to register the user MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email, userId); if (createStatus == MembershipCreateStatus.Success) { _context.Users.InsertOnSubmit(new User() { Id = userId, Credits = 0 }); _context.SubmitChanges(); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus)); } } return(View(model)); }
public void UpdateStatus(int bid) { var obj = db.Banners.SingleOrDefault(b => b.ID == bid); obj.Status = !obj.Status; db.SubmitChanges(); }
public void Delete(int nid) { var obj = db.Newsletters.SingleOrDefault(n => n.NewsID == nid); db.Newsletters.DeleteOnSubmit(obj); db.SubmitChanges(); }
/// <summary> /// Update the roles to security user /// </summary> public override Core.Model.Security.SecurityApplication Update(ModelDataContext context, Core.Model.Security.SecurityApplication data, IPrincipal principal) { var domainInstance = this.FromModelInstance(data, context, principal) as Data.SecurityApplication; var currentObject = context.GetTable <Data.SecurityApplication>().FirstOrDefault(ExpressionRewriter.Rewrite <Data.SecurityApplication>(o => o.Id == data.Key)); if (currentObject == null) { throw new KeyNotFoundException(data.Key.ToString()); } currentObject.CopyObjectData(domainInstance); currentObject.ObsoletedBy = data.ObsoletedByKey == Guid.Empty ? null : data.ObsoletedByKey; currentObject.ObsoletionTime = data.ObsoletionTime; context.SubmitChanges(); context.SecurityApplicationPolicies.DeleteAllOnSubmit(context.SecurityApplicationPolicies.Where(o => o.ApplicationId == domainInstance.Id)); context.SubmitChanges(); context.SecurityApplicationPolicies.InsertAllOnSubmit(data.Policies.Select(o => new Data.SecurityApplicationPolicy { PolicyId = o.PolicyKey.Value, PolicyAction = (int)o.GrantType, ApplicationId = domainInstance.Id, SecurityPolicyInstanceId = Guid.NewGuid() })); context.SubmitChanges(); return(data); }
public void UpdateStockAndBought(int serial, int number) { var obj = db.Products.SingleOrDefault(p => p.Serial == serial); obj.UnitInStock -= number; obj.Bought += number; db.SubmitChanges(); }
public void Update(Other o) { var obj = db.Others.SingleOrDefault(ob => ob.ID == o.ID); obj.Name = o.Name; obj.Content = o.Content; obj.ParentsID = o.ParentsID; db.SubmitChanges(); }
public bool Insert(Category _category) { try { db.Categories.InsertOnSubmit(_category); db.SubmitChanges(); return(true); } catch (Exception) { return(false); } }
public bool Insert(Book _Book) { try { db.Books.InsertOnSubmit(_Book); db.SubmitChanges(); return(true); } catch (Exception) { return(false); } }
public string UpdateProduct(int id, Product product) { try { ModelDataContext db = new ModelDataContext(); var query = from p in db.Products where p.ID == id select p; foreach (Product p in query) { p.Name = product.Name; p.ProductNumber = product.ProductNumber; p.ManufactureDate = product.ManufactureDate; p.Price = product.Price; p.Stock = product.Stock; p.CategoryID = product.CategoryID; p.Image = product.Image; } db.SubmitChanges(); return(product.Name + " updated successfully."); } catch (Exception e) { return("Error: " + e); } }
private void onInsert() { try { using (ModelDataContext mdc = new ModelDataContext()) { Model.Aluno aluno = new Model.Aluno() { Nome = tbNome.Text.Trim(), Endereco = tbEndereco.Text.Trim(), Cep = tbCep.Text.Trim(), Telefone = tbTelefone.Text.Trim(), Celular = tbCelular.Text.Trim(), dataNascimento = DateTime.Parse(tbDataNasc.Text.Trim()), dataCadastro = DateTime.Parse(DateTime.Now.ToShortDateString()) }; mdc.Aluno.InsertOnSubmit(aluno); mdc.SubmitChanges(); Response.Redirect("Aluno.aspx"); } } catch (Exception) { } }
private void CalculaMedia() { mdc = new ModelDataContext(); try { Model.Notas notas = new Model.Notas(); if (notas.a3 != null) { var media = (notas.a1 + notas.a2 + notas.a3) / 3; notas.media = media; } else if (notas.a2 != null) { var media = (notas.a1 + notas.a2) / 2; notas.media = media; } mdc.Notas.InsertOnSubmit(notas); mdc.SubmitChanges(); Response.Redirect("Notas.aspx?id=" + Request.QueryString["id"]); } catch (Exception) { throw; } finally { mdc.Dispose(); } }
public void InsertUserInformation(AdminTable info) { ModelDataContext db = new ModelDataContext(); db.AdminTables.InsertOnSubmit(info); db.SubmitChanges(); }
public void InsertUserInformation(UserInformation info) { ModelDataContext db = new ModelDataContext(); db.UserInformations.InsertOnSubmit(info); db.SubmitChanges(); }
private void onInsert() { mdc = new ModelDataContext(); try { Loja loja = new Loja(); loja.IdLoja = int.Parse(tbIdLoja.Text.Trim()); loja.Loja1 = tbLoja.Text.Trim(); loja.DataCadastro = DateTime.Parse(lblDataCadastro.Text.Trim()); loja.Endereco = tbEndereco.Text.Trim(); loja.Celular = tbTelefone.Text.Trim(); loja.Cep = tbCep.Text.Trim(); loja.Cidade = tbCidade.Text.Trim(); loja.Municipio = tbMunicipio.Text.Trim(); loja.UF = tbUF.Value.ToString(); mdc.Lojas.InsertOnSubmit(loja); mdc.SubmitChanges(); Response.Write("<script language=javascript>alert('Cadastro efetuado com sucesso!!!');window.location.href='Loja_Add.aspx';</script>"); } catch (Exception) { Response.Write("<script language=javascript>alert('Cadastro Existente !!!');window.location.href='Loja_Add.aspx';</script>"); } finally { mdc.Dispose(); } }
private void OnInsert() { mdc = new ModelDataContext(); try { Materia materia = new Materia(); materia.Nome = tbNome.Text.Trim(); materia.Descricao = tbDescriao.Text.Trim(); materia.dataCadastro = Convert.ToDateTime(tbDataCadastro.Text.Trim()); mdc.Materia.InsertOnSubmit(materia); mdc.SubmitChanges(); Response.Redirect("Materias.aspx"); } catch (Exception) { throw; } finally { mdc.Dispose(); } }
private void OnUpdate() { mdc = new ModelDataContext(); try { Model.Aluno aluno = mdc.Aluno.First(alu => alu.idAluno == int.Parse(tbCodAluno.Text.Trim())); aluno.Nome = tbNome.Text.Trim(); aluno.Endereco = tbEndereco.Text.Trim(); aluno.Cep = tbCep.Text.Trim(); aluno.Telefone = tbTelefone.Text.Trim(); aluno.Celular = tbCelular.Text.Trim(); aluno.dataNascimento = DateTime.Parse(tbDataNasc.Text.Trim()); aluno.dataAtualizacao = DateTime.Parse(DateTime.Now.ToShortDateString()); mdc.SubmitChanges(); Response.Redirect("Aluno.aspx"); } catch (Exception) { throw; } finally { mdc.Dispose(); } }
public string UpdateOrder(int id, Order order) { try { ModelDataContext db = new ModelDataContext(); var query = from p in db.Orders where p.ID == id select p; foreach (Order p in query) { p.ClientID = order.ClientID; p.ProductID = order.ProductID; p.OrderQuantity = order.OrderQuantity; p.OrderDate = order.OrderDate; p.IsInCart = order.IsInCart; } db.SubmitChanges(); return(order.OrderDate + " updated successfully."); } catch (Exception e) { return("Error: " + e); } }
/// <summary> /// Delete the specified identity /// </summary> public void DeleteIdentity(string userName, IPrincipal authContext) { if (String.IsNullOrEmpty(userName)) { throw new ArgumentNullException(nameof(userName)); } this.m_traceSource.TraceInformation("Delete identity {0}", userName); try { // submit the changes using (var dataContext = new ModelDataContext(this.m_configuration.ReadWriteConnectionString)) { new PolicyPermission(System.Security.Permissions.PermissionState.Unrestricted, PermissionPolicyIdentifiers.UnrestrictedAdministration, authContext).Demand(); var user = dataContext.SecurityUsers.FirstOrDefault(o => o.UserName == userName); if (user == null) { throw new KeyNotFoundException("Specified user does not exist!"); } // Obsolete user.ObsoletionTime = DateTimeOffset.Now; user.ObsoletedByEntity = authContext.GetUser(dataContext); user.SecurityStamp = Guid.NewGuid().ToString(); dataContext.SubmitChanges(); } } catch (Exception e) { this.m_traceSource.TraceEvent(TraceEventType.Error, e.HResult, e.ToString()); throw; } }
public string Verify(String id) { try { ModelDataContext db = new ModelDataContext(); var query = from p in db.UserInformations where p.GUID == id select p; foreach (UserInformation p in query) { /*UserInformation info = new UserInformation(); * info.FirstName = p.FirstName; * info.LastName = p.LastName; * info.Address = p.Address; * info.Phone = p.Phone; * info.PostalCode = p.PostalCode; * info.Email = p.Email; * info.Username = p.Username; * info.Password=p.Password;*/ p.IsVerified = true; } db.SubmitChanges(); return("verified."); } catch (Exception e) { return("Error: " + e); } }
private void onInsert() { mdc = new ModelDataContext(); try { Model.Curso curso = new Model.Curso(); curso.idAluno = 1; curso.idMateria = 1; curso.Nome = tbNome.Text.Trim(); curso.Descricao = tbDescricao.Text.Trim(); curso.dataCadastro = Convert.ToDateTime(tbDataCadastro.Text.Trim()); mdc.Curso.InsertOnSubmit(curso); mdc.SubmitChanges(); Response.Redirect("Curso.aspx"); } catch (Exception) { throw; } finally { mdc.Dispose(); } }
private void OnInsert() { mdc = new ModelDataContext(); try { Model.Turma turma = new Model.Turma(); turma.idMateria = int.Parse(tbCodMaterias.Text.Trim()); turma.Nome = tbNome.Text.Trim(); turma.dataCadastro = Convert.ToDateTime(tbDataCadastro.Text.Trim()); mdc.Turma.InsertOnSubmit(turma); mdc.SubmitChanges(); Response.Redirect("Turma.aspx"); } catch (Exception) { throw; } finally { mdc.Dispose(); } }
/// <summary> /// Perform the actual update. /// </summary> /// <param name="context">Context.</param> /// <param name="data">Data.</param> public override TModel Update(ModelDataContext context, TModel data, IPrincipal principal) { // Check for key if (data.Key == Guid.Empty) { throw new SqlFormalConstraintException(SqlFormalConstraintType.NonIdentityUpdate); } // Get current object var domainObject = this.FromModelInstance(data, context, principal) as TDomain; var currentObject = context.GetTable <TDomain>().FirstOrDefault(ExpressionRewriter.Rewrite <TDomain>(o => o.Id == data.Key)); // Not found if (currentObject == null) { throw new KeyNotFoundException(data.Key.ToString()); } // VObject var vobject = domainObject as IDbNonVersionedBaseData; if (vobject != null) { vobject.UpdatedBy = principal.GetUser(context).UserId; vobject.UpdatedTime = DateTimeOffset.Now; } currentObject.CopyObjectData(domainObject); context.SubmitChanges(); return(this.ToModelInstance(domainObject, context, principal)); }
public void linqEntityAndPhotos(List <int> PhotoId, int UserId) { using (var db = new ModelDataContext()) { var photo = db.Photos.Where(l => PhotoId.Contains(l.PhotoId)).ToList(); photo.ForEach(l => { l.ObjectId = UserId; l.ObjectName = "Users"; }); db.SubmitChanges(); } }
/// <summary> /// Create a basic user /// </summary> public IIdentity CreateIdentity(string userName, string password, IPrincipal authContext) { if (String.IsNullOrEmpty(userName)) { throw new ArgumentNullException(nameof(userName)); } else if (String.IsNullOrEmpty(password)) { throw new ArgumentNullException(nameof(password)); } else if (authContext == null) { throw new ArgumentNullException(nameof(authContext)); } this.m_traceSource.TraceInformation("Creating identity {0} ({1})", userName, authContext); try { using (var dataContext = new ModelDataContext(this.m_configuration.ReadWriteConnectionString)) { var hashingService = ApplicationContext.Current.GetService <IPasswordHashingService>(); var pdpService = ApplicationContext.Current.GetService <IPolicyDecisionService>(); // Demand create identity new PolicyPermission(System.Security.Permissions.PermissionState.Unrestricted, PermissionPolicyIdentifiers.CreateIdentity, authContext).Demand(); // Does this principal have the ability to Data.SecurityUser newIdentityUser = new Data.SecurityUser() { UserId = Guid.NewGuid(), UserName = userName, UserPassword = hashingService.EncodePassword(password), SecurityStamp = Guid.NewGuid().ToString(), UserClass = UserClassKeys.HumanUser }; if (authContext != null) { newIdentityUser.CreatedByEntity = dataContext.SecurityUsers.Single(u => u.UserName == authContext.Identity.Name); } dataContext.SecurityUsers.InsertOnSubmit(newIdentityUser); dataContext.SubmitChanges(); return(SqlClaimsIdentity.Create(newIdentityUser)); } } catch (Exception e) { this.m_traceSource.TraceEvent(TraceEventType.Error, e.HResult, e.ToString()); throw; } }
/// <summary> /// Update the data with new version information /// </summary> public override TModel Update(ModelDataContext context, TModel data, IPrincipal principal) { if (data.Key == Guid.Empty) { throw new SqlFormalConstraintException(SqlFormalConstraintType.NonIdentityUpdate); } // This is technically an insert and not an update var existingObject = context.GetTable <TDomain>().FirstOrDefault(ExpressionRewriter.Rewrite <TDomain>(o => o.Id == data.Key && !o.ObsoletionTime.HasValue)); // Get the last version (current) if (existingObject == null) { throw new KeyNotFoundException(data.Key.ToString()); } else if (existingObject.IsReadonly) { throw new SqlFormalConstraintException(SqlFormalConstraintType.UpdatedReadonlyObject); } // Map existing var storageInstance = this.FromModelInstance(data, context, principal); // Create a new version var user = principal.GetUser(context); var newEntityVersion = new TDomain(); newEntityVersion.CopyObjectData(storageInstance); // Client did not change on update, so we need to update!!! if (!data.VersionKey.HasValue || data.VersionKey.Value == existingObject.VersionId) { data.VersionKey = newEntityVersion.VersionId = Guid.NewGuid(); } data.VersionSequence = newEntityVersion.VersionSequenceId = default(Decimal); newEntityVersion.Id = data.Key.Value; data.PreviousVersionKey = newEntityVersion.ReplacesVersionId = existingObject.VersionId; data.CreatedByKey = newEntityVersion.CreatedBy = user.UserId; // Obsolete the old version existingObject.ObsoletedBy = user.UserId; existingObject.ObsoletionTime = DateTime.Now; context.GetTable <TDomain>().InsertOnSubmit(newEntityVersion); context.SubmitChanges(); // Pull database generated fields data.VersionSequence = newEntityVersion.VersionSequenceId; data.CreationTime = newEntityVersion.CreationTime; return(data); //return base.Update(context, data, principal); }
public void UpdateQuantity(int id, int quantity) { ModelDataContext db = new ModelDataContext(); var query = from p in db.Orders where p.ID == id select p; foreach (Order p in query) { p.OrderQuantity = quantity; } db.SubmitChanges(); }
/// <summary> /// Add a claim to the specified user /// </summary> public void AddClaim(string userName, Claim claim) { if (userName == null) { throw new ArgumentNullException(nameof(userName)); } else if (claim == null) { throw new ArgumentNullException(nameof(claim)); } try { using (var dataContext = new ModelDataContext(this.m_configuration.ReadWriteConnectionString)) { var user = dataContext.SecurityUsers.FirstOrDefault(o => o.UserName == userName); if (user == null) { throw new KeyNotFoundException(userName); } lock (this.m_syncLock) { var existingClaim = dataContext.SecurityUserClaims.FirstOrDefault(o => o.ClaimType == claim.Type && o.UserId == user.Id); // Set the secret if (existingClaim == null) { dataContext.SecurityUserClaims.InsertOnSubmit(new SecurityUserClaim() { ClaimId = Guid.NewGuid(), ClaimType = claim.Type, ClaimValue = claim.Value, SecurityUser = user }); } else { existingClaim.ClaimValue = claim.Value; } dataContext.SubmitChanges(); } } } catch (Exception e) { this.m_traceSource.TraceEvent(TraceEventType.Error, e.HResult, e.ToString()); throw; } }
public string insertOrder(Order order) { try { ModelDataContext db = new ModelDataContext(); db.Orders.InsertOnSubmit(order); db.SubmitChanges(); return(order.OrderDate + "inserted successfully"); } catch (Exception msg) { return(msg.ToString()); } }
public bool merge(KeyWordDTO entity) { try { var addObj = (from p in ctx.KeyWords where p.word == @entity.word && p.vacancyNumber == @entity.vacancyNumber select p).Single(); model.KeyWord obj = (KeyWord)addObj; /*Update*/ obj.word = entity.word; obj.vacancyNumber = entity.vacancyNumber; ctx.SubmitChanges(); return true; } catch (Exception e) { model.Log log = new Log(); log.message = "KeyWord Merge: " + " [" + entity.word + " , " + entity.vacancyNumber + "] " + e.Message; ctx.Dispose(); ctx = new ModelDataContext(); ctx.SubmitChanges(); return false; } }
protected void SignUp_Click(object sender, EventArgs e) { try { Datamanager dtm = new Datamanager(); ModelDataContext mod = new ModelDataContext(); UvaRequest uvReq = new UvaRequest(); string userUvaId = uvReq.GetUvaUserIdByUsername(txt_uvauser.Text); if (userUvaId != null && !userUvaId.Equals("0") && !userUvaId.Equals("")) { MembershipUser user = Membership.CreateUser(txt_uvauser.Text, txt_password.Text, txt_email.Text); Guid id = (Guid)user.ProviderUserKey; int intUserUvaId = int.Parse(userUvaId); Usuario us = new Usuario() { Nombre = txt_name.Text, IdUser = id, Universidad = txt_uni.Text, Uname = txt_uvauser.Text, Uid = intUserUvaId }; mod.Usuarios.InsertOnSubmit(us); mod.SubmitChanges(); //FormsAuthentication.SetAuthCookie(txt_name.Text, false); Response.Redirect("Login.aspx"); } else { if (userUvaId.Equals("")) Msg.Text = "Hubo un problema con el servidor de uHunt intenta el registro más tarde."; if (userUvaId == null||userUvaId.Equals("0")) Msg.Text = "Usuario de Uva no esta registrado"; } } catch (System.Web.Security.MembershipCreateUserException ex) { switch (ex.StatusCode) { case MembershipCreateStatus.DuplicateEmail: Msg.Text = "Email está en uso"; break; case MembershipCreateStatus.DuplicateProviderUserKey: Msg.Text = "DPUK"; break; case MembershipCreateStatus.DuplicateUserName: Msg.Text = "Usuario está en uso"; break; case MembershipCreateStatus.InvalidAnswer: Msg.Text = "Respuesta Invalida"; break; case MembershipCreateStatus.InvalidEmail: Msg.Text = "Email inválido"; break; case MembershipCreateStatus.InvalidPassword: Msg.Text = "Contraseña inválida"; break; case MembershipCreateStatus.InvalidProviderUserKey: Msg.Text = "Invalid Provider User Key"; break; case MembershipCreateStatus.InvalidQuestion: Msg.Text = "Invalid Question"; break; case MembershipCreateStatus.InvalidUserName: Msg.Text = "Usuario Inválido"; break; case MembershipCreateStatus.ProviderError: Msg.Text = "Provider Error"; break; case MembershipCreateStatus.Success: Msg.Text = "Succes!"; break; case MembershipCreateStatus.UserRejected: Msg.Text = "User Rejected"; break; default: break; } } //MembershipUser current = // Membership.GetUser(); //if (current != null) //{ //} //TODO: Crear usuario en la otra tabla }
public bool merge(AddressDTO entity) { try { var addObj = (from p in ctx.Addresses where p.userName == @entity.userName && p.addressType == @entity.addressType select p).Single(); model.Address obj = (Address)addObj; /*Update*/ obj.userName = entity.userName; obj.addressType = entity.addressType; obj.unitNumber = entity.unitNumber; obj.street = entity.street; obj.suburb = entity.suburb; obj.town = entity.town; obj.province = entity.province; obj.country = entity.country; ctx.SubmitChanges(); return true; } catch (Exception e) { model.Log log = new Log(); log.message = "Address Merge: " + " ["+entity.userName+" , "+entity.addressType+"] " + e.Message; ctx.Dispose(); ctx = new ModelDataContext(); ctx.SubmitChanges(); return false; } }
public bool merge(ApplicationDTO entity) { try { var addObj = (from p in ctx.Applications where p.userName == @entity.userName && p.vacancyNumber == @entity.vacancyNumber select p).Single(); model.Application obj = (Application)addObj; /*Update*/ obj.userName = entity.userName; obj.vacancyNumber = entity.vacancyNumber; obj.status = entity.status; ctx.SubmitChanges(); return true; } catch (Exception e) { model.Log log = new Log(); log.message = "Application Merge: " + " [" + entity.userName + " , " + entity.vacancyNumber + "] " + e.Message; ctx.Dispose(); ctx = new ModelDataContext(); ctx.SubmitChanges(); return false; } }
public bool merge(ContactInfoDTO entity) { try { var addObj = (from p in ctx.ContactInfos where p.userName == @entity.userName && p.contactType == @entity.contactType select p).Single(); model.ContactInfo obj = (ContactInfo)addObj; /*Update*/ obj.userName = entity.userName; obj.contactType = entity.contactType; obj.data = entity.data; ctx.SubmitChanges(); return true; } catch (Exception e) { model.Log log = new Log(); log.message = "ContactInfo Merge: " + " ["+entity.userName+" , "+entity.contactType+"] " + e.Message; ctx.Dispose(); ctx = new ModelDataContext(); ctx.SubmitChanges(); return false; } }
public bool merge(BasicEduSubjectDTO entity) { try { var addObj = (from p in ctx.BasicEduSubjects where p.userName == @entity.userName && p.subjectName == @entity.subjectName select p).Single(); model.BasicEduSubject obj = (BasicEduSubject)addObj; /*Update*/ obj.userName = entity.userName; obj.subjectName = entity.subjectName; obj.subjectDescription = entity.subjectDescription; ctx.SubmitChanges(); return true; } catch (Exception e) { model.Log log = new Log(); log.message = "BasicEduSubject Merge: " + " ["+entity.userName+" , "+entity.subjectName+"] " + e.Message; ctx.Dispose(); ctx = new ModelDataContext(); ctx.SubmitChanges(); return false; } }