Esempio n. 1
0
        internal static void CreateTicket(Ticket newTicket)
        {
            using (ManagementEntity context = new ManagementEntity())
            {
                try
                {
                    Models.Management.Ticket ticket = new Models.Management.Ticket();

                    ticket.Created = DateTime.FromBinary(newTicket.Date);
                    ticket.Description = newTicket.Description;
                    ticket.Type = (int)newTicket.TicketType;
                    ticket.EmployeeId = newTicket.EmployeeID;
                    ticket.AutoNumber = newTicket.CarNumber;
                    ticket.DepartmentId = newTicket.DepartmentID;
                    ticket.CustomerId = newTicket.CustomerID;

                    ticket.Status = 1;      ///Ticket status: 0 - closed, 1 - opened

                    context.Tickets.AddObject(ticket);
                    context.SaveChanges();
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }
        }
Esempio n. 2
0
        internal static void CloseTicket(int ticketID)
        {
            using (ManagementEntity context = new ManagementEntity())
            {
                try
                {
                    var ticketToClose =
                        (from t in context.Tickets where t.Id == ticketID select t).FirstOrDefault();

                    if (ticketToClose != null)
                    {
                        ticketToClose.Closed = DateTime.Now;
                        context.TicketHistories.AddObject(new TicketHistory
                                                            {
                                                                Ticket = ticketToClose,
                                                            }
                                                        );
                        context.SaveChanges();
                    }
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }
        }
Esempio n. 3
0
        public static void CreatePayment(Payment newPayment)
        {
            using (ManagementEntity context = new ManagementEntity())
            {
                try
                {
                    Models.Management.Payment payment = new Models.Management.Payment
                    {
                        TicketId = newPayment.TicketID,
                        OrderId = newPayment.OrderID,
                        Type = (int)e_PaymentStatus.NotPaid,//default is not paid
                        Amount = newPayment.Amount,
                        Date = DateTime.UtcNow,
                        Destination = newPayment.Destination
                    };

                    context.Payments.AddObject(payment);
                    context.SaveChanges();

                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }
        }
Esempio n. 4
0
        public static IList<Modules.Management.Order> GetOrders()
        {
            IList<Modules.Management.Order> orders = new List<Modules.Management.Order>();

            using (ManagementEntity context = new ManagementEntity())
            {
                try
                {
                    var orderList =
                        (from ol in context.Orders select ol);

                    foreach (var order in orderList)
                    {
                        Autorent.Modules.Management.Order o = new Order();
                        o.ID = order.Number;
                        o.StartDateRent = (int)order.CreationDate.ToBinary();
                        o.ClientID = order.CustomerId;
                        o.ManagerID = order.ManagerId;
                        o.CarNumber = order.AutoNumber;
                        o.StatusOrder = (e_StatusOrder)order.Status;
                        o.Type = (OrderType)order.Type;
                        o.XMLData = order.Data;

                        orders.Add(o);
                    }
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }

            return orders;
        }
Esempio n. 5
0
        public static void AddOrder(Order newOrder)
        {
            using (ManagementEntity context = new ManagementEntity())
            {
                try
                {
                    Models.Management.Order order = new Models.Management.Order();

                    order.CustomerId = newOrder.ClientID;
                    order.CreationDate = DateTime.Now;
                    order.AutoNumber = newOrder.CarNumber;
                    order.ManagerId = newOrder.ManagerID;
                    order.Type = (int)newOrder.Type;

                    order.Status = (int)e_StatusOrder.NotProcessed;

                    context.Orders.AddObject(order);
                    context.SaveChanges();
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }
        }
Esempio n. 6
0
        public static IList<Payment> GetPayments()
        {
            IList<Payment> paymentList = new List<Payment>();

            using (ManagementEntity context = new ManagementEntity())
            {
                try
                {
                    var queryPayments = from p in context.Payments select p;

                    foreach (var item in queryPayments)
                    {
                        Payment payment = new Payment();
                        payment.ID = item.Id;
                        payment.TicketID = item.TicketId;
                        payment.OrderID = item.OrderId;
                        payment.CustomerID = item.CustomerId;
                        payment.PaymentStatus = (e_PaymentStatus)item.Type;
                        payment.Amount = item.Amount;
                        payment.Date = (int)item.Date.ToBinary();
                        payment.Destination = item.Destination;

                        paymentList.Add(payment);
                    }
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }

            return paymentList;
        }
Esempio n. 7
0
        public static IList<Department> GetDepartments()
        {
            IList<Department> departments = new List<Department>();

            using (ManagementEntity context = new ManagementEntity())
            {
                try
                {
                    var listOfDepartments =
                        (from d in context.Departments select d);

                    if (listOfDepartments != null)
                    {
                        foreach (var item in listOfDepartments)
                        {
                            Department department = new Department();

                            department.ID = item.Id;
                            department.Address = item.Addresse;
                            department.Name = item.Name;
                            department.PhoneNumber = item.Phone;

                            departments.Add(department);
                        }
                    }
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }

            return departments;
        }
Esempio n. 8
0
        public static void DeletePayment(int paymentID)
        {
            using (ManagementEntity context = new ManagementEntity())
            {
                try
                {
                    var queryPayment = (from p in context.Payments where p.Id == paymentID select p).FirstOrDefault();

                    context.DeleteObject(queryPayment);
                    context.SaveChanges();
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }
        }
Esempio n. 9
0
        public static void DeleteOrder(int orderID)
        {
            using (ManagementEntity context = new ManagementEntity())
            {
                try
                {
                    var orderToDelete =
                        (from o in context.Orders where o.Number == orderID select o).FirstOrDefault();

                    if (orderToDelete != null)
                    {
                        context.Orders.DeleteObject(orderToDelete);
                        context.SaveChanges();
                    }
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }
        }
Esempio n. 10
0
        public static void DeleteDepartment(Department department)
        {
            using (ManagementEntity context = new ManagementEntity())
            {
                try
                {
                    var deptToDelete =
                        (from d in context.Departments where d.Id == department.ID select d).FirstOrDefault();

                    if (deptToDelete != null)
                    {
                        context.Departments.DeleteObject(deptToDelete);
                        context.SaveChanges();
                    }
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }
        }
Esempio n. 11
0
        internal static void DeleteTicket(int ticketID)
        {
            using (ManagementEntity context = new ManagementEntity())
            {
                try
                {
                    var ticketToDelete =
                        (from t in context.Tickets where t.Id == ticketID select t).FirstOrDefault();

                    if (ticketToDelete != null)
                    {
                        context.DeleteObject(ticketToDelete);
                        context.SaveChanges();
                    }
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }
        }
Esempio n. 12
0
        public static void CreateDepartment(Department department)
        {
            using (ManagementEntity context = new ManagementEntity())
            {
                try
                {
                    Models.Management.Department dept = new Models.Management.Department();

                    dept.Id = department.ID;
                    dept.Name = department.Name;
                    dept.Phone = department.PhoneNumber;
                    dept.Addresse = department.Address;

                    context.Departments.AddObject(dept);
                    context.SaveChanges();
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }
        }
Esempio n. 13
0
        internal static void SaveTickets(IList<Modules.Management.Ticket> tickets)
        {
            using (ManagementEntity context = new ManagementEntity())
            {
                try
                {
                    foreach (var item in tickets)
                    {
                        var ticketToSave =
                            (from t in context.Tickets where t.Id == item.ID select t).FirstOrDefault();

                        if (ticketToSave != null)
                        {
                            ticketToSave.OrderNumber = item.OrderID;
                            ticketToSave.Description = item.Description;
                            ticketToSave.Created = DateTime.FromBinary(item.Date);
                            ticketToSave.Type = (int)item.TicketType;
                            ticketToSave.EmployeeId = item.EmployeeID;
                            ticketToSave.AutoNumber = item.CarNumber;
                            ticketToSave.DepartmentId = item.DepartmentID;
                            ticketToSave.CustomerId = item.CustomerID;

                            context.SaveChanges();

                            List<int> i = new List<int>();
                        }
                    }
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }
        }
Esempio n. 14
0
        public static void UpdateOrder(Modules.Management.Order order)
        {
            using (ManagementEntity context = new ManagementEntity())
            {
                try
                {
                    var queryOrder = (from o in context.Orders where o.Number == order.ID select o).FirstOrDefault();
                    queryOrder.AutoNumber = order.CarNumber;
                    queryOrder.CustomerId = order.ClientID;
                    queryOrder.ManagerId = order.ManagerID;
                    queryOrder.CreationDate = DateTime.FromBinary(order.CreationDate);
                    queryOrder.ExpiredDate = DateTime.FromBinary(order.EndDateRent);
                    queryOrder.Type = (int)order.Type;
                    queryOrder.Status = (int)order.StatusOrder;
                    queryOrder.Data = order.XMLData;

                    context.SaveChanges();

                    Random rnd = new Random(order.ID);
                    int newTicketID = rnd.Next(1, int.MaxValue);

                    Autorent.Modules.Management.Ticket newTicket = new Autorent.Modules.Management.Ticket
                    {
                        CarNumber = order.CarNumber,
                        CustomerID = order.ClientID,
                        Date = (int)DateTime.Now.ToBinary(),
                        DepartmentID = Guid.NewGuid(),
                        EmployeeID = order.ManagerID,
                        OrderID = order.ID,
                        ID = newTicketID,
                        TicketType = TicketType.CarMigration
                    };

                    TicketAPI.CreateTicket(newTicket);

                    Autorent.Modules.Management.Payment newPayment = new Autorent.Modules.Management.Payment
                    {
                        Amount = rnd.Next(1100, 3500),
                        CustomerID = order.ClientID.Value,
                        Date = (int)DateTime.Now.ToBinary(),
                        Destination = "RosPilUa",
                        OrderID = order.ID,
                        PaymentStatus = e_PaymentStatus.NotPaid,
                        TicketID = newTicketID
                    };

                    PaymentAPI.CreatePayment(newPayment);

                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }
        }
Esempio n. 15
0
        public static void UpdatePayment(int paymentID, e_PaymentStatus paymentStatus, decimal amount, string destination)
        {
            using (ManagementEntity context = new ManagementEntity())
            {
                try
                {
                    var queryPayment = (from p in context.Payments where p.Id == paymentID select p).FirstOrDefault();
                    queryPayment.Type = (int)paymentStatus;
                    queryPayment.Amount = amount;
                    queryPayment.Destination = destination;

                    context.SaveChanges();
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }
        }
Esempio n. 16
0
        public static void UpdateDepartment(Guid departmentID, string departmentName, string address, string phoneNumber)
        {
            using (ManagementEntity context = new ManagementEntity())
            {
                try
                {
                    var dept =
                        (from d in context.Departments where d.Id == departmentID select d).FirstOrDefault();

                    if (dept != null)
                    {
                        dept.Name = departmentName;
                        dept.Addresse = address;
                        dept.Phone = phoneNumber;

                        context.SaveChanges();
                    }
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }
        }
Esempio n. 17
0
        internal static IList<Ticket> GetTickets()
        {
            IList<Ticket> tickets = new List<Ticket>();

            using (ManagementEntity context = new ManagementEntity())
            {
                try
                {
                    var ticketsList =
                        (from tl in context.Tickets select tl);

                    foreach (var ticket in ticketsList)
                    {
                        Autorent.Modules.Management.Ticket t = new Ticket();
                        t.Date = (int)ticket.Created.ToBinary();
                        t.Description = ticket.Description;
                        t.OrderID = (int)ticket.OrderNumber;
                        t.TicketType = (TicketType)ticket.Type;
                        t.CarNumber = ticket.AutoNumber;
                        t.EmployeeID = ticket.EmployeeId;
                        t.DepartmentID = ticket.DepartmentId;
                        t.CustomerID = ticket.CustomerId;

                        tickets.Add(t);
                    }
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }

            return tickets;
        }
Esempio n. 18
0
        public static void SaveOrders(IList<Management.Order> orders)
        {
            using (ManagementEntity context = new ManagementEntity())
            {
                try
                {
                    foreach (var item in orders)
                    {
                        var orderToSave =
                            (from o in context.Orders where o.Number == item.ID select o).FirstOrDefault();

                        if (orderToSave != null)
                        {
                            orderToSave.Number = item.ID;
                            orderToSave.CreationDate = DateTime.FromBinary(item.StartDateRent);
                            orderToSave.CustomerId = item.ClientID;
                            orderToSave.ManagerId = item.ManagerID;
                            orderToSave.AutoNumber = item.CarNumber;
                            orderToSave.Status = (int)item.StatusOrder;
                            orderToSave.Type = (int)item.Type;
                            orderToSave.Data = item.XMLData;

                            context.SaveChanges();
                        }
                    }
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }
        }