public ExpandoObject Add(string name, double x, double y) { try { var entityTemp = new entity { name = name, coord = new coord() { x = (long)x, y = (long)y } }; _context.entities.Add(entityTemp); _context.SaveChanges(); dynamic entityDynamic = new ExpandoObject(); entityDynamic.id = entityTemp.id; entityDynamic.name = entityTemp.name; entityDynamic.x = (double)entityTemp.coord.x; entityDynamic.y = (double)entityTemp.coord.y; return(entityDynamic); } catch (OverflowException) { return(null); //Not ecpected overflow (solution change type of the property in the datbase to contains double //TODO: log error and implement a nice error message } }
public long Add(Seller seller) { seller.Id = 0; _context.Entry(seller).State = EntityState.Added; _context.SaveChanges(); return(seller.Id); }
public bool Update(PurechasesHeader purechasesHeader) { _context.Entry(purechasesHeader).State = EntityState.Modified; _context.SaveChanges(); DeletePurchaseDetails(purechasesHeader.Id); SetPurechasesHeaderId(purechasesHeader.Id, purechasesHeader.PurechasesDetialsList); AddPurechasesDetials(purechasesHeader.PurechasesDetialsList, _context); _safeOperationsRepo.UpdateByHeaderId(purechasesHeader.Id, purechasesHeader.Total, AccountTypesEnum.Clients); return(true); }
public bool Update(Order_Purechase entity) { Order_Purechase order_Purechase = _context.Order_Purechases.FirstOrDefault(x => x.OrderHeaderId == entity.OrderHeaderId); if (order_Purechase != null) { order_Purechase.PurechasesHeaderId = entity.PurechasesHeaderId; } _context.SaveChanges(); return(true); }
public long Add(Farmer farmer) { try { _context.Entry(farmer).State = EntityState.Added; _context.SaveChanges(); return(farmer.Id); } catch (Exception ex) { System.IO.File.WriteAllText(@"e:\errorLog.txt", ex.Message); throw ex; } }
public bool Add(UserDTO userDTO) { User user = Map(userDTO); context.Entry(user).State = EntityState.Added; var result = context.SaveChanges(); if (result > 0) { SaveProfileImage(user.ImageUrl, userDTO.ImageBase64); return(true); } return(false); }
public bool Add(Role role) { try { context.Entry(role).State = EntityState.Added; context.SaveChanges(); return(true); } catch (Exception ex) { System.IO.File.WriteAllText(@"e:\errorLog.txt", ex.Message); throw ex; } }
private void DeletePurchaseDetails(long headerId, EntitiesDbContext context) { IEnumerable <PurechasesDetials> purchaseDetails = context.PurechasesDetials.Where(x => x.PurechasesHeaderId == headerId); context.PurechasesDetials.RemoveRange(purchaseDetails); context.SaveChanges(); }
private void DeleteSalesinvoicesDetials(long headerId, EntitiesDbContext context) { IEnumerable <SalesinvoicesDetials> purchaseDetails = context.SalesinvoicesDetials.Where(x => x.SalesinvoicesHeaderId == headerId).AsEnumerable(); context.SalesinvoicesDetials.RemoveRange(purchaseDetails); context.SaveChanges(); }
public bool DeleteRelatedOrderDetials(long headerId, EntitiesDbContext context) { IEnumerable <OrderDetails> orderDetails = context.OrderDetails.Where(x => x.OrderHeaderId == headerId); context.OrderDetails.RemoveRange(orderDetails); context.SaveChanges(); return(true); }
public List <SalesinvoicesDetials> DeleteSalesinvoiceDetails(OrderHeader orderHeader, EntitiesDbContext context) { List <SalesinvoicesDetials> salesinvoicesDetialsList = _context.SalesinvoicesDetials.Where(x => x.OrderDate == orderHeader.Created).ToList(); context.SalesinvoicesDetials.RemoveRange(salesinvoicesDetialsList); context.SaveChanges(); return(salesinvoicesDetialsList); }
public bool Add(PurechasesHeader purechasesHeader, EntitiesDbContext context) { context.Entry(purechasesHeader).State = EntityState.Added; context.SaveChanges(); SetPurechasesHeaderId(purechasesHeader.Id, purechasesHeader.PurechasesDetialsList); AddPurechasesDetials(purechasesHeader.PurechasesDetialsList, context); return(true); }
public bool Delete(long id, EntitiesDbContext context) { OrderHeader OrderHeader = GetById(id, context); context.OrderHeaders.Remove(OrderHeader); context.SaveChanges(); return(true); }
public bool Delete(long id, EntitiesDbContext context) { PurechasesHeader purechasesHeader = GetById(id); DeletePurchaseDetails(id); context.PurechasesHeaders.Remove(purechasesHeader); context.SaveChanges(); return(true); }
public ActionResult Create([Bind(Include = "EntityName,Description")] Entity entity) { if (ModelState.IsValid) { entity.EntityGuid = Guid.NewGuid(); entity.DateCreated = DateTime.Now; entity.DateModified = entity.DateCreated; entity.UserCreatedID = Auxiliaries.GetUserId(User); entity.UserModifiedID = Auxiliaries.GetUserId(User); db.Entities.Add(entity); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(entity)); }
public bool Delete(long id, EntitiesDbContext context) { SalesinvoicesHeader salesinvoicesHeader = GetById(id, context); DeleteSalesinvoicesDetials(id, context); context.SalesinvoicesHeaders.Remove(salesinvoicesHeader); context.SaveChanges(); return(true); }
public bool Update(SalesinvoicesHeader salesinvoicesHeader, EntitiesDbContext context) { context.SalesinvoicesHeaders.Update(salesinvoicesHeader); context.SaveChanges(); //DeleteSalesinvoicesDetials(salesinvoicesHeader.Id, context); //SetSalesinvoicesHeaderId(salesinvoicesHeader, salesinvoicesHeader.SalesinvoicesDetialsList); //AddSalesinvoicesDetials(salesinvoicesHeader.SalesinvoicesDetialsList, context); //UpdateSalesinvoiceTotal(salesinvoicesHeader.SalesinvoicesDetialsList, context); return(true); }
public bool DeleteByHeaderId(long header, AccountTypesEnum accountTypesEnum, EntitiesDbContext context) { Safe safe = context.Safes.SingleOrDefault(x => x.HeaderId == header && x.AccountTypeId == (int)accountTypesEnum); if (safe != null) { context.Safes.Remove(safe); context.SaveChanges(); return(true); } return(false); }
public bool DeleteByOrderId(long orderId, EntitiesDbContext context) { List <Safe> safes = context.Safes.Where(x => x.OrderId == orderId).ToList(); if (safes != null) { context.Safes.RemoveRange(safes); context.SaveChanges(); return(true); } return(false); }
public SalesinvoicesHeader Add(SalesinvoicesHeader salesinvoicesHeader, long orderHeaderId, EntitiesDbContext context) { //To-Do //Check if Seller has at least one salesinvoice at this day or no SalesinvoicesHeader exsistedSalesHeader = GetSalesinvoiceHeaderByDateAndSellerId(salesinvoicesHeader.SalesinvoicesDate, salesinvoicesHeader.SellerId, context); if (exsistedSalesHeader == null)//It is the first salesinvoice to this Seller in this day { context.Entry(salesinvoicesHeader).State = EntityState.Added; context.SaveChanges(); } if (salesinvoicesHeader.Id == 0) { salesinvoicesHeader.Id = exsistedSalesHeader.Id; } SetSalesinvoicesHeaderId(salesinvoicesHeader, salesinvoicesHeader.SalesinvoicesDetialsList); //Set SalesinvoiceHeaderId AddSalesinvoicesDetials(salesinvoicesHeader.SalesinvoicesDetialsList, context); //Add SalesinvoiceDetails return(UpdateSalesinvoiceTotal(salesinvoicesHeader.SalesinvoicesDetialsList, context)); //Return updated salesinvoiceHeader }
public bool UpdateByHeaderId(long headerId, decimal total, AccountTypesEnum accountTypesEnum, EntitiesDbContext context) { Safe safe = context.Safes.FirstOrDefault(x => x.HeaderId == headerId && x.AccountTypeId == (int)accountTypesEnum); if (safe != null) { if (accountTypesEnum == AccountTypesEnum.Sellers) { safe.Outcoming = total; } else { safe.Incoming = total; } context.Safes.Update(safe); context.SaveChanges(); return(true); } return(false); }
private SalesinvoicesHeader UpdateSalesinvoiceTotal(IEnumerable <SalesinvoicesDetials> salesinvoicesDetialsList, EntitiesDbContext context) { decimal total = 0; //Calculate Total decimal mashalTotal = 0; //Calculate Mashal Total decimal byaaTotal = 0; //Calculate Byaa Total long salesHeaderId = 0; foreach (SalesinvoicesDetials item in salesinvoicesDetialsList) { salesHeaderId = item.SalesinvoicesHeaderId; total += (item.Weight * item.Price) + (AppSettings.MashalRate + AppSettings.ByaaRate) * item.Quantity; mashalTotal += AppSettings.MashalRate * item.Quantity; byaaTotal += AppSettings.ByaaRate * item.Quantity; } SalesinvoicesHeader salesinvoicesHeader = context.SalesinvoicesHeaders.SingleOrDefault(x => x.Id == salesHeaderId); salesinvoicesHeader.Total = salesinvoicesHeader.Total + total; salesinvoicesHeader.MashalTotal = salesinvoicesHeader.MashalTotal + mashalTotal; salesinvoicesHeader.ByaaTotal = salesinvoicesHeader.ByaaTotal + byaaTotal; context.SaveChanges(); return(salesinvoicesHeader); }
/// <summary> /// Method that adds an employee to the database /// </summary> /// <param name="employee"> /// Employee to be added /// </param> public void AddEmployee(Employee employee) { _context.Add(employee); _context.SaveChanges(); return; }
private void AddSalesinvoicesDetials(IEnumerable <SalesinvoicesDetials> salesinvoicesDetialsList, EntitiesDbContext context) { context.SalesinvoicesDetials.AddRange(salesinvoicesDetialsList); context.SaveChanges(); }
public void Save() { _db.SaveChanges(); }
public Order Create(Order order) { context.Orders.Add(order); context.SaveChanges(); return(order); }
public bool Add(Order_Purechase entity, EntitiesDbContext context) { context.Order_Purechases.Add(entity); context.SaveChanges(); return(true); }
public bool Update(OrderHeader entity, EntitiesDbContext context) { context.Entry(entity).State = EntityState.Modified; context.SaveChanges(); return(true); }
public bool Add(OrderHeader entity, EntitiesDbContext context) { context.OrderHeaders.Add(entity); context.SaveChanges(); return(true); }
public int Commit() { return(_ctx.SaveChanges()); }