internal static bool UpdateMol(CommonMol oldMol) { DatabaseEntities entities = new DatabaseEntities(); MOL dbMol = entities.MOLs.FirstOrDefault(p => p.MolId == oldMol.MolId); if (dbMol == null) { return(false); } dbMol.FirstName = oldMol.FirstName; dbMol.Address = oldMol.Address; dbMol.Email = oldMol.Email; dbMol.Phone = oldMol.Phone; dbMol.LastName = oldMol.LastName; entities.MOLs.Attach(dbMol); var entry = entities.Entry(dbMol); entry.Property(e => e.FirstName).IsModified = true; entry.Property(e => e.Address).IsModified = true; entry.Property(e => e.Email).IsModified = true; entry.Property(e => e.Phone).IsModified = true; entry.Property(e => e.LastName).IsModified = true; entities.SaveChanges(); return(true); }
public ActionResult DeleteConfirmed(int id) { MOL mOL = db.MOL.Find(id); db.MOL.Remove(mOL); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "id_mol,molname,birthday,arivaldate")] MOL mOL) { if (ModelState.IsValid) { db.Entry(mOL).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(mOL)); }
internal static bool DeleteMol(Guid molId) { DatabaseEntities entities = new DatabaseEntities(); MOL mol = entities.MOLs.FirstOrDefault(p => p.MolId == molId); if (mol != null) { entities.MOLs.Remove(mol); entities.SaveChanges(); return(true); } return(false); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MOL mOL = db.MOL.Find(id); if (mOL == null) { return(HttpNotFound()); } return(View(mOL)); }
public ActionResult Create([Bind(Include = "id_mol,molname,birthday,arivaldate")] MOL mOL) { if (ModelState.IsValid) { db.MOL.Add(mOL); db.SaveChanges(); if (TempData["HomePage"].Equals("/Functions")) { return(RedirectToAction("Functions", "Home")); } return(RedirectToAction("Index")); } return(View(mOL)); }
public void RemoveObject(CollisionObject simObject) { foreach (List <CollisionObject> MOL in MeshedObjectIndexes()) { lock (MOL) if (MOL.Contains(simObject)) { OccupiedCount--; if (simObject.IsSolid) { IsSolid--; } TaintMatrix(); MOL.Remove(simObject); } } }
internal static bool CreateMol(CommonMol newMol) { DatabaseEntities entities = new DatabaseEntities(); MOL mol = new MOL(); mol.OwnerId = newMol.OwnerId; mol.Address = newMol.Address; mol.Email = newMol.Email; mol.FirstName = newMol.FirstName; mol.LastName = newMol.LastName; mol.Phone = newMol.Phone; mol.MolId = Guid.NewGuid(); mol.IsPrimary = false; entities.MOLs.Add(mol); entities.SaveChanges(); return(true); }
public ActionResult Index([Bind(Include = "id_mol,molname,birthday,arivaldate")] MOL mOL) { IEnumerable <MOL> mols = db.MOL.ToList(); if (!mOL.arivaldate.Equals(new DateTime(1, 1, 1, 0, 0, 0))) { mols = mols.Where(m => m.arivaldate == mOL.arivaldate); } if (!mOL.birthday.Equals(new DateTime(1, 1, 1, 0, 0, 0))) { mols = mols.Where(m => m.birthday == mOL.birthday); } if (mOL.molname != null) { mols = mols.Where(m => m.molname == mOL.molname); } TempData["HomePage"] = "Index"; return(View(mols.OrderBy(MOL => MOL.molname))); }
internal static CommonMol ChangePrimary(Guid oldMolId, Guid newMolId) { CommonMol result = new CommonMol(); DatabaseEntities entities = new DatabaseEntities(); MOL dbMol = entities.MOLs.FirstOrDefault(p => p.MolId == oldMolId); if (dbMol != null) { dbMol.IsPrimary = false; entities.MOLs.Attach(dbMol); var entry = entities.Entry(dbMol); entry.Property(e => e.IsPrimary).IsModified = true; entities.SaveChanges(); } MOL newPrimeryMol = entities.MOLs.FirstOrDefault(p => p.MolId == newMolId); if (newPrimeryMol != null) { newPrimeryMol.IsPrimary = true; entities.MOLs.Attach(newPrimeryMol); var entry = entities.Entry(newPrimeryMol); entry.Property(e => e.IsPrimary).IsModified = true; result.MolId = newPrimeryMol.MolId; result.IsPrimery = newPrimeryMol.IsPrimary; result.OwnerId = newPrimeryMol.OwnerId; result.Address = newPrimeryMol.Address; result.Email = newPrimeryMol.Email; result.FirstName = newPrimeryMol.FirstName; result.LastName = newPrimeryMol.LastName; result.Phone = newPrimeryMol.Phone; entities.SaveChanges(); } return(result); }
internal static CommonSale CreateSale(CommonSale sale, int documentType, bool isWhole = false) { try { bool checker = true; DatabaseEntities entities = new DatabaseEntities(); foreach (var item in sale.SoldItems) { WarehouseItem whItem = entities.WarehouseItems.FirstOrDefault(p => p.ItemId == item.ItemId); if (whItem?.Quantity < item.Quantity) { checker = false; } } if (checker) { foreach (var item in sale.SoldItems) { WarehouseItem whItem = entities.WarehouseItems.FirstOrDefault(p => p.ItemId == item.ItemId); if (whItem != null) { whItem.Quantity = whItem.Quantity.Value - item.Quantity; entities.WarehouseItems.Attach(whItem); var entry = entities.Entry(whItem); entry.Property(e => e.Quantity).IsModified = true; } } Sale s = new Sale(); s.BuyerId = sale.BuyerId; s.Date = DateTime.Now; s.DocumentId = null; s.SellerId = sale.SellerId; s.SoldItems = new List <SoldItem>(); Guid tempGuid = NewGuid(); s.SaleId = tempGuid; //// //// FIX payment completed after payment completed interface is ready. for now all are true; //// s.PaymentCompleted = true; //// //// ///// foreach (var item in sale.SoldItems) { var i = new SoldItem { ItemId = item.ItemId, Price = item.Price * 100, Quantity = item.Quantity, SaleId = s.SaleId, SoldItemId = NewGuid() }; s.SoldItems.Add(i); } if (isWhole) { var document = new Document(); document.PartnerId = s.BuyerId; document.OwnerId = s.SellerId; document.SaleId = s.SaleId; document.InvoiceId = NewGuid(); document.DocumentType = documentType; DocumentTypeCounter docType = entities.DocumentTypeCounters.FirstOrDefault(p => p.DocumentType == documentType); if (docType != null) { Counter currentCounter = docType.Counter; document.InvoiceNumber = currentCounter.CurrentNumber + 1 ?? 1; currentCounter.CurrentNumber = document.InvoiceNumber; entities.Counters.Attach(currentCounter); var entry = entities.Entry(currentCounter); entry.Property(e => e.CurrentNumber).IsModified = true; entities.SaveChanges(); } Partner partner = entities.Partners.FirstOrDefault(p => p.PartnerId == s.BuyerId); if (partner != null) { document.BuyerAddress = partner.Address; document.BuyerBulstat = partner.Bulstat; document.BuyerCompanyName = partner.CompanyName; document.BuyerVATNumber = partner.VATNumber; MOL mol = entities.MOLs.FirstOrDefault(p => p.OwnerId == partner.PartnerId); document.BuyerMol = mol != null ? $"{mol.FirstName} {mol.LastName}" : ""; decimal counter = 0; foreach (var item in s.SoldItems) { WarehouseItem whItem = entities.WarehouseItems.FirstOrDefault(p => p.ItemId == item.ItemId); counter += ((decimal)whItem.SellingPriceCent.Value / 100) * item.Quantity; } partner.Sum += counter; List <PartnerDiscount> discount = entities.PartnerDiscounts.ToList(); foreach (PartnerDiscount t in discount) { if (partner.Sum >= t.RangeFrom && partner.Sum <= t.RangeTo) { if (partner.PartnerType == t.PartnerType) { document.DiscountPercent = t.Discount; } else { partner.PartnerType = t.PartnerType; document.DiscountPercent = t.Discount; } } } entities.Partners.Attach(partner); var entry = entities.Entry(partner); entry.Property(e => e.Sum).IsModified = true; entry.Property(e => e.PartnerType).IsModified = true; entities.SaveChanges(); } Owner owner = entities.Owners.First(); document.OwnerAddress = owner.Address; document.OwnerBank = owner.Bank; document.OwnerBulstat = owner.Bulstat; document.OwnerIBAN = owner.IBAN; document.OwnerCompanyName = owner.CompanyName; document.OwnerSwiftCode = owner.SWIFTCode; document.OwnerVATNumber = owner.VATNumber; MOL mol2 = entities.MOLs.FirstOrDefault(p => p.OwnerId == owner.OwnerId && p.IsPrimary); if (mol2 != null) { document.OwnerMol = $"{mol2.FirstName} {mol2.LastName}"; } s.Document = document; } entities.Sales.Add(s); entities.SaveChanges(); sale.Date = s.Date; sale.BuyerId = s.BuyerId; sale.SaleId = s.SaleId; sale.SellerId = s.SellerId; sale.Type = s.Type; if (isWhole) { sale.InvoiceId = s.Document.InvoiceNumber.ToString(); } sale.SoldItems = new List <CommonSoldItem>(); //// FIx payment completed sale.PaymentCompleted = true; foreach (var h in s.SoldItems) { var item = new CommonSoldItem(); item.ItemId = h.ItemId; item.Price = h.Price; item.Quantity = h.Quantity; item.SaleId = h.SaleId; sale.SoldItems.Add(item); } return(sale); } return(null); } catch (Exception e) { return(null); } }