public string CreateCommunication(CreateCommunicationDto data) { try { if (data.SenderId < 1 || data.ReceiverId < 1) { throw new InvalidSenderOrReceiverException(data.SenderId, data.ReceiverId); } var communicationForType = _context.Communications .Where(x => x.Type == data.Type); var record = data.Type == Type.External ? $"CE00000{communicationForType.Count() + 1}" : $"CI00000{communicationForType.Count() + 1}"; var newCommunication = new Communication(record, data.SenderId, data.ReceiverId, data.Type); _context.Add(newCommunication); _context.SaveChanges(); return(record); } catch (InvalidSenderOrReceiverException exception) { return(exception.Message); } }
public ActionResult Create([Bind(Include = "CustomerID,DateOfBirth,DateOfDeath,FirstName,LastName,RecordGuid,RCD,LMD,RowVersion")] Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Create([Bind(Include = "CustomerID,PersonID,IsActive,RecordGuid,RCD,LMD,RowVersion")] Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PersonID = new SelectList(db.People, "PersonID", "PersonType", customer.PersonID); return(View(customer)); }
public static void UpdateEmployee(Employee employee) { try { using (var db = new AlphaContext()) { var tempEmployee = db.Employees.Single(x => x.Id == employee.Id); tempEmployee.FirstName = employee.FirstName; tempEmployee.LastName = employee.LastName; tempEmployee.Title = employee.Title; tempEmployee.BirthDate = employee.BirthDate; tempEmployee.HireDate = employee.HireDate; tempEmployee.Address = employee.Address; tempEmployee.City = employee.City; tempEmployee.HomePage = employee.HomePage; tempEmployee.Photo = employee.Photo; tempEmployee.PhotoPath = employee.PhotoPath; tempEmployee.ReportTo = employee.ReportTo; db.SaveChanges(); } } catch (Exception exception) { LogManage.Log("MethodName:UpdateEmployee " + Environment.NewLine + " Time: " + DateTime.Now + Environment.NewLine + " ErrorMsg: " + exception.Message); } }
public User Create(NewUserDto data) { var newUser = new User(data.FullName, data.Email, data.Role, data.PassWord); _context.Add(newUser); _context.SaveChanges(); return(newUser); }
public static void InsertCustomer(Customer customer) { try { using (var db = new AlphaContext()) { db.Customers.Add(customer); db.SaveChanges(); } } catch (Exception exception) { LogManage.Log("MethodName:InsertCustomer " + Environment.NewLine + " Time: " + DateTime.Now + Environment.NewLine + " ErrorMsg: " + exception.Message); } }
public static void InsertProduct(Product product) { try { using (var db = new AlphaContext()) { db.Products.Add(product); db.SaveChanges(); } } catch (Exception exception) { LogManage.Log("MethodName:InsertProduct " + Environment.NewLine + " Time: " + DateTime.Now + Environment.NewLine + " ErrorMsg: " + exception.Message); } }
public static void InsertEmployee(Employee employee) { try { using (var db = new AlphaContext()) { db.Employees.Add(employee); db.SaveChanges(); } } catch (Exception exception) { LogManage.Log("MethodName:InsertEmployee " + Environment.NewLine + " Time: " + DateTime.Now + Environment.NewLine + " ErrorMsg: " + exception.Message); } }
public static void InsertOrderDetail(OrderDetail orderDetail) { try { using (var db = new AlphaContext()) { db.OrderDetails.Add(orderDetail); db.SaveChanges(); } } catch (Exception exception) { LogManage.Log("MethodName:InsertOrderDetail " + Environment.NewLine + " Time: " + DateTime.Now + Environment.NewLine + " ErrorMsg: " + exception.Message); } }
public static void DeleteCategory(int categoryId) { try { using (var db = new AlphaContext()) { var tempCategory = db.Categories.Single(x => x.Id == categoryId); db.Categories.Remove(tempCategory); db.SaveChanges(); } } catch (Exception exception) { LogManage.Log("MethodName:DeleteCategory " + Environment.NewLine + " Time: " + DateTime.Now + Environment.NewLine + " ErrorMsg: " + exception.Message); } }
public static void DeleteOrderDetail(int orderDetailId) { try { using (var db = new AlphaContext()) { var tempOrderDetail = db.OrderDetails.Single(x => x.Id == orderDetailId); db.OrderDetails.Remove(tempOrderDetail); db.SaveChanges(); } } catch (Exception exception) { LogManage.Log("MethodName:DeleteOrderDetail " + Environment.NewLine + " Time: " + DateTime.Now + Environment.NewLine + " ErrorMsg: " + exception.Message); } }
public static void DeleteSupplier(int supplierId) { try { using (var db = new AlphaContext()) { var tempSupplier = db.Suppliers.Single(x => x.Id == supplierId); db.Suppliers.Remove(tempSupplier); db.SaveChanges(); } } catch (Exception exception) { LogManage.Log("MethodName:DeleteSupplier " + Environment.NewLine + " Time: " + DateTime.Now + Environment.NewLine + " ErrorMsg: " + exception.Message); } }
public static void DeleteProduct(int productId) { try { using (var db = new AlphaContext()) { var tempProduct = db.Products.Single(x => x.Id == productId); db.Products.Remove(tempProduct); db.SaveChanges(); } } catch (Exception exception) { LogManage.Log("MethodName:DeleteProduct " + Environment.NewLine + " Time: " + DateTime.Now + Environment.NewLine + " ErrorMsg: " + exception.Message); } }
public static void UpdateCategory(Category category) { try { using (var db = new AlphaContext()) { var tempCategory = db.Categories.Single(x => x.Id == category.Id); tempCategory.CategoryName = category.CategoryName; tempCategory.Description = category.Description; tempCategory.Picture = category.Picture; db.SaveChanges(); } } catch (Exception exception) { LogManage.Log("MethodName:UpdateCategory " + Environment.NewLine + " Time: " + DateTime.Now + Environment.NewLine + " ErrorMsg: " + exception.Message); } }
public static void UpdateOrderDetail(OrderDetail orderDetail) { try { using (var db = new AlphaContext()) { var tempOrderDetail = db.OrderDetails.Single(x => x.Id == orderDetail.Id); tempOrderDetail.ProductId = orderDetail.ProductId; tempOrderDetail.Product = orderDetail.Product; tempOrderDetail.UnitPrice = orderDetail.UnitPrice; tempOrderDetail.Quantity = orderDetail.Quantity; tempOrderDetail.Discount = orderDetail.Discount; db.SaveChanges(); } } catch (Exception exception) { LogManage.Log("MethodName:UpdateOrderDetail " + Environment.NewLine + " Time: " + DateTime.Now + Environment.NewLine + " ErrorMsg: " + exception.Message); } }
public static void UpdateOrder(Order order) { try { using (var db = new AlphaContext()) { var tempOrder = db.Orders.Single(x => x.Id == order.Id); tempOrder.OrderDate = order.OrderDate; tempOrder.CustomerId = order.CustomerId; tempOrder.EmployeeId = order.EmployeeId; tempOrder.Employee = order.Employee; tempOrder.Discount = order.Discount; tempOrder.NetTotal = order.NetTotal; db.SaveChanges(); } } catch (Exception exception) { LogManage.Log("MethodName:UpdateOrder " + Environment.NewLine + " Time: " + DateTime.Now + Environment.NewLine + " ErrorMsg: " + exception.Message); } }
public static void Initialize(AlphaContext context) { context.Database.EnsureCreated(); if (context.Users.Any()) { return; } var users = new [] { new User("Fercho Administrador", "*****@*****.**", Role.Admin, "Lolita"), new User("Pepito destinatario", "*****@*****.**", Role.Destinater, "destinater") }; foreach (var user in users) { context.Users.Add(user); } context.SaveChanges(); }
public static void UpdateCustomer(Customer customer) { try { using (var db = new AlphaContext()) { var tempCustomer = db.Customers.Single(x => x.Id == customer.Id); tempCustomer.CompanyName = customer.CompanyName; tempCustomer.ContactName = customer.CompanyName; tempCustomer.ContactTitle = customer.ContactTitle; tempCustomer.Address = customer.Address; tempCustomer.City = customer.City; tempCustomer.Phone = customer.Phone; tempCustomer.Fax = customer.Fax; db.SaveChanges(); } } catch (Exception exception) { LogManage.Log("MethodName:UpdateCustomer " + Environment.NewLine + " Time: " + DateTime.Now + Environment.NewLine + " ErrorMsg: " + exception.Message); } }
public static void UpdateProduct(Product product) { try { using (var db = new AlphaContext()) { var tempProduct = db.Products.Single(x => x.Id == product.Id); tempProduct.Quantity = product.Quantity; tempProduct.ProductName = product.ProductName; tempProduct.Supplier = product.Supplier; tempProduct.CategoryId = product.CategoryId; tempProduct.SupplierId = product.SupplierId; tempProduct.UnitPrice = product.UnitPrice; tempProduct.UnitsInStock = product.UnitsInStock; tempProduct.Discountinued = product.Discountinued; db.SaveChanges(); } } catch (Exception exception) { LogManage.Log("MethodName:UpdateProduct " + Environment.NewLine + " Time: " + DateTime.Now + Environment.NewLine + " ErrorMsg: " + exception.Message); } }