public CustomerEntity Find(String CustomerCode) { using (var db = new ModelDb()) { return(db.Customers.Where(c => c.CustomerIsActive && c.CustomerCode == CustomerCode).FirstOrDefault()); } }
public ProductEntity Find(Guid ProductID) { using (var db = new ModelDb()) { return(db.Products.Where(c => c.ProductIsActive && c.ProductID == ProductID).FirstOrDefault()); } }
public ProductEntity Find(String ProductCode) { using (var db = new ModelDb()) { return(db.Products.Where(c => c.ProductIsActive && c.ProductCode == ProductCode).FirstOrDefault()); } }
/// <summary> /// Permite guardar un producto. /// </summary> /// <param name="Product">Objeto producto con sus datos</param> /// <returns>Si no hay ningún problema al guardar, este retorna el UNIQUEID generado al producto.</returns> public ProductEntity Save(ProductEntity Product) { //Validando datos this.Validation(Product); //Validando Código var pExist = this.Find(Product.ProductCode); if (pExist != null) // Si existe, entra { throw new Exception("Ya existe un producto con este Código"); } using (var db = new ModelDb()) { Product.ProductID = Guid.NewGuid(); Product.ProductIsActive = true; //guardar producto db.Products.Add(Product); db.SaveChanges(); } return(Product); }
public SalesOrderService(ModelDb db, UnitOfWork unitOfWork, ICustomerService customerService, IHttpContextAccessor httpContextAccessor) { this.db = db; this.customerService = customerService; this.unitOfWork = unitOfWork; this.httpContextAccessor = httpContextAccessor; }
public void Update(T entity) { using (var db = new ModelDb()) { db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); } }
public List <LineEntity> List() { using (var db = new ModelDb()) { return(db.Lines .AsParallel() .OrderBy(c => c.LineName) .ToList()); } }
public List <MarkEntity> List() { using (var db = new ModelDb()) { return(db.Marks .AsParallel() .OrderBy(c => c.MarkName) .ToList()); } }
public List <ProductEntity> List(string ProductCode = "", string ProductName = "", decimal ProductPrice = 0, string ProductMark = "", string ProductLine = "", Boolean ProductState = true) { var db = new ModelDb(); var productList = db.Products .Where(c => c.ProductCode.Contains(ProductCode) && // Filtrando por código c.ProductName.Contains(ProductName) && // Filtrando por nombre c.ProductIsActive.Equals(ProductState) // Filtrando por estado ); //Filtrando por precio if (ProductPrice > 0) { productList = productList .Where(c => c.ProductPrice == ProductPrice ); } //Filtrando por marca if (ProductMark != null) { if (ProductMark.Trim() != "") { productList = productList .Where(c => c.MarkID != null ) .Where(c => c.Mark.MarkName.Contains(ProductMark) ); } } //Filtrando por linea if (ProductLine != null) { if (ProductLine.Trim() != "") { productList = productList .Where(c => c.LineID != null ) .Where(c => c.Line.LineName.Contains(ProductLine) ); } } //Retornando la lista return(productList.ToList()); }
public ActionResult Index() { var roles = new Models.UserRoles(); roles.Id = Guid.NewGuid().ToString(); roles.Name = ""; ModelDb db = new ModelDb(); db.UserRoles.Add(roles); db.SaveChanges(); return(View()); }
public UnitOfWork(bool lazyLoadingEnabled, bool proxyCreationEnabled) { string fullName = System.Diagnostics.Process.GetCurrentProcess().ProcessName; context = ModelDb.Create(); if (fullName == "Win") { context = ModelDb.Create(DataSource.ConnectionString); } ; //(/*DataSource.ConnectionString ?? context.Database.Connection.ConnectionString*/); this.context.Configuration.LazyLoadingEnabled = lazyLoadingEnabled; this.context.Configuration.ProxyCreationEnabled = proxyCreationEnabled; }
/// <summary> /// Permite guardar un cliente. /// </summary> /// <param name="Customer">Objeto cliente con sus datos</param> /// <returns>Si no hay ningún problema al guardar, este retorna el UNIQUEID generado al cliente.</returns> public Guid Save(CustomerEntity Customer) { using (var db = new ModelDb()) { Customer.CustomerID = Guid.NewGuid(); Customer.CustomerIsActive = true; //Guardamos el cliente db.Customers.Add(Customer); db.SaveChanges(); } return(Customer.CustomerID); }
public MarkEntity Save(MarkEntity Mark) { this.Validation(Mark); using (var db = new ModelDb()) { Mark.MarkID = Guid.NewGuid(); db.Marks.Add(Mark); db.SaveChanges(); return(Mark); } }
public ActionResult Login(clsUsers login) { ModelDb db = new ModelDb(); int userId = 0; bool status = false; string Message = string.Empty; // clsPasswordEncrypt encrypt = new clsPasswordEncrypt(); //string password = encrypt.GetHash(login.Password); string hashPassword = clsPasswordEncrypt.GetHash(login.Password); var user = (from u in db.tblUsers where u.UserName.ToLower() == login.UserName.ToLower().Trim() && u.Password == hashPassword select u).FirstOrDefault(); if (user != null) { status = true; Message = "Login Successfully"; status = true; string[] roles = new string[1]; roles[0] = "User"; CustomPrincipalSerializeModel serializeModel = new CustomPrincipalSerializeModel(); serializeModel.UserId = user.Id; serializeModel.Name = user.FirstName + " " + user.LastName; serializeModel.roles = roles; string userData = JsonConvert.SerializeObject(serializeModel); FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( 1, user.FirstName + " " + user.LastName, DateTime.Now, DateTime.Now.AddMinutes(30), false, userData); string encTicket = FormsAuthentication.Encrypt(authTicket); HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket); Response.Cookies.Add(faCookie); status = true; userId = user.Id; } else { status = false; Message = "Please Enter Correct Username or Password!"; } var jsonResult = Json(new { status = status, message = Message, UserId = userId }, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = Int32.MaxValue; return(jsonResult); }
public UnitOfWork() { string fullName = System.Diagnostics.Process.GetCurrentProcess().ProcessName; context = ModelDb.Create(); if (fullName == "Win") { context = ModelDb.Create(DataSource.ConnectionString); } //(/*DataSource.ConnectionString ?? context.Database.Connection.ConnectionString*/); }
public void Delete(Guid ProductID) { using (var db = new ModelDb()) { var Product = this.Find(ProductID); if (Product != null) { Product.ProductIsActive = false; db.Entry(Product).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } }
public LineEntity Save(LineEntity Line) { this.Validation(Line); using (var db = new ModelDb()) { Line.LineID = Guid.NewGuid(); db.Lines.Add(Line); db.SaveChanges(); return(Line); } }
public void Delete(Guid CustomerID) { using (var db = new ModelDb()) { var Customer = this.Find(CustomerID); if (Customer != null) { Customer.CustomerIsActive = false; db.Entry(Customer).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } }
private DbViewModel() : base() { Db = new ModelDb(); try { foreach (var el in Db.Files) { Files.Add(new WpfApp15.Model.Files(el)); } } catch (Exception er) { MessageBox.Show(er.Message, "Error"); } }
public UnitOfWork(ModelDb db, IGenericRepository <SalesOrderDetails> salesOrderDetailRepo, IGenericRepository <SalesOrders> salesOrderRepo, IGenericRepository <SalesOrderPayments> salesOrderPaymentRepo, IGenericRepository <Cheques> chequesRepo, IGenericRepository <Inventory> inventoryRepo, IGenericRepository <TransformationMaps> transformationMapsRepo ) { this.context = db; this.SalesOrderDetailRepo = salesOrderDetailRepo; this.SalesOrderRepo = salesOrderRepo; this.SalesOrderPaymentRepo = salesOrderPaymentRepo; this.ChequesRepo = chequesRepo; this.InventoryRepo = inventoryRepo; this.TransformationMapsRepo = transformationMapsRepo; }
private async void BtnLogin_Click(object sender, EventArgs e) { UnitOfWork unitOfWork = new UnitOfWork(); unitOfWork = new UnitOfWork(); ApplicationUserManager userManager = new ApplicationUserManager(new UserStores(ModelDb.Create())); var user = await userManager.FindByNameAsync(txtUserName.Text); if (user == null) { MessageBox.Show("Invalid UserName", "Invalid UserName", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var res = userManager.PasswordHasher.VerifyHashedPassword(user.PasswordHash, txtPassword.Text); if (res != Microsoft.AspNet.Identity.PasswordVerificationResult.Success) { MessageBox.Show("Invalid Password", "Invalid Password", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (chkRemember.Checked) { Settings.Default.UserName = txtUserName.Text; Settings.Default.Password = txtPassword.Text; Settings.Default.RememberMe = chkRemember.Checked; Settings.Default.Save(); } else { Settings.Default.UserName = string.Empty; Settings.Default.Password = string.Empty; Settings.Default.RememberMe = false; Settings.Default.Save(); } User.UserId = user.Id; isClosed = true; this.Close(); }
public void Edit(ProductEntity Product) { //Validando datos this.Validation(Product); using (var db = new ModelDb()) { //Se carga el producto var p = db.Products.Where(c => c.ProductID == Product.ProductID).FirstOrDefault(); //Se verifica que existe if (p != null) { //Validando Código var pExist = this.Find(Product.ProductCode); if (pExist != null) // Si existe, entra { if (pExist.ProductID != p.ProductID) { throw new Exception("Ya existe un producto con este Código"); } } //Se editan los datos p.ProductCode = Product.ProductCode; p.ProductName = Product.ProductName; p.ProductPrice = Product.ProductPrice; p.ProductDescription = Product.ProductDescription; p.MarkID = Product.MarkID; p.LineID = Product.LineID; //Se prepara para la edición db.Entry(p).State = System.Data.Entity.EntityState.Modified; //Se guardan los datos db.SaveChanges(); } } }
public static void Main(string[] param) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); BonusSkins.Register(); // var res = Cryptography.Decrypt("LQzNKovDgd5lrVJO1gypjDqxF4cqbri6uKOYkra19ko="); MachineTime.SetSystemTimeZone("Taipei Standard Time"); MachineTime.SetFormat(); //Application.Run(new Main(param)); //Application.Run(new frmConfirmationTemplates(new Models.Templates(), Models.MethodType.Add)); ModelDb db = new ModelDb(); db.Database.Log = (s) => { Debug.WriteLine(s); }; var res = db.Obligations.Select(x => new { TotalAmount = db.ORDetails.Sum(m => m.Amount) }); Debug.WriteLine(res.Sum(x => x.TotalAmount)); }
public GenericRepository(ModelDb context) { this.context = context; this.dbSet = context.Set <TEntity>(); context.ChangeTracker.LazyLoadingEnabled = true; }
public GenericRepository(ModelDb context) { this.context = context; this.dbSet = context.Set <TEntity>(); }
public SalesOrderDetailService(ModelDb db, IProductService productService) { this.db = db; this.productService = productService; }
internal AccountManagement() { this._model = new ModelDb(); }
public ActionResult InsertUpdateCustomerAccount(clsUsers user) { string message = ""; bool status = false; using (ModelDb db = new ModelDb()) { try { string returnId = "0"; string insertUpdateStatus = ""; int? AccountId = user.Id; if (user.Id > 0) { insertUpdateStatus = "Update"; bool check = db.tblUsers.Where(x => x.Id == AccountId).Any(x => x.UserName.ToLower().Trim() == user.UserName.ToLower().Trim()); if (!check) { bool check2 = db.tblUsers.Any(x => x.UserName.ToLower().Trim() == user.UserName.ToLower().Trim()); if (check2) { status = false; message = "User already exist."; return(new JsonResult { Data = new { status = status, message = message } }); } } if (user.StatusString == "Active") { user.Status = true; } else { user.Status = false; } if (!(string.IsNullOrEmpty(user.Password))) { user.Password = clsPasswordEncrypt.GetHash(user.Password); } } else { insertUpdateStatus = "Save"; bool check2 = db.tblUsers.Any(x => x.UserName.ToLower().Trim() == user.UserName.ToLower().Trim()); if (check2) { status = false; message = "User already exist."; return(new JsonResult { Data = new { status = status, message = message } }); } user.Status = true; if (!(string.IsNullOrEmpty(user.Password))) { user.Password = clsPasswordEncrypt.GetHash(user.Password); } } clsResult result = InsertUpdateCustomerDb(user, insertUpdateStatus); if (result.ResultMessage == "Success") { ModelState.Clear(); status = true; message = "User Successfully Registered."; user.Id = result.Id; } else { ModelState.Clear(); status = false; message = result.ResultMessage; user.Id = 0; } } catch (Exception ex) { status = false; message = ex.Message.ToString(); } } return(new JsonResult { Data = new { status = status, message = message, id = user.Id } }); }
public Maintenance(ModelDb db) { this.db = db; }
public GenericRepository(ModelDb context) { this.context = context; context.Database.Log = (s) => { Debug.WriteLine(s); }; this.dbSet = context.Set <TEntity>(); }