Example #1
0
        public Model.Order InsertOrUpdate(Model.Order order)
        {
            using (var context = new DataModelDataContext())
            {
                Order target = null;
                if (order.Id != Guid.Empty)
                {
                    target = context.Orders.SingleOrDefault(e => e.Id == order.Id);
                    if (target == null)
                    {
                        return(null);
                    }
                    target.State = order.State;
                }
                else
                {
                    target = new Order
                    {
                        Id        = Guid.NewGuid(),
                        State     = "ManagerApproving",
                        StateName = "Manager approving",
                    };
                    context.Orders.InsertOnSubmit(target);
                }
                target.OwnerId = order.OwnerId;
                context.SubmitChanges();

                order.Id = target.Id;
                return(order);
            }
        }
Example #2
0
        public Model.Employee InsertOrUpdate(Model.Employee employee)
        {
            using (var context = new DataModelDataContext())
            {
                Employee target = null;
                if (employee.Id != Guid.Empty)
                {
                    target = context.Employees.SingleOrDefault(e => e.Id == employee.Id);
                    if (target == null)
                    {
                        return(null);
                    }
                }
                else
                {
                    target = new Employee
                    {
                        Id = Guid.NewGuid(),
                    };
                    context.Employees.InsertOnSubmit(target);
                }
                target.Name   = employee.Name;
                target.RoleId = employee.RoleId;
                context.SubmitChanges();

                employee.Id = target.Id;
                return(employee);
            }
        }
Example #3
0
        private Order Get(Guid id, DataModelDataContext context)
        {
            var order = context.Orders.FirstOrDefault(c => c.Id == id);

            if (order == null)
            {
                return(null);
            }
            return(order);
        }
Example #4
0
 public Guid Login(string username, string password)
 {
     using (var context = new DataModelDataContext())
     {
         var account = context.Accounts.FirstOrDefault(a => a.Username == username && a.Password == password);
         if (account != null)
         {
             return(account.EmployeeId);
         }
     }
     return(Guid.Empty);
 }
Example #5
0
 public List <Model.Order> Get()
 {
     using (var context = new DataModelDataContext())
     {
         var result = context.Orders.Select(o => Mappings.Mapper.Map <Model.Order>(o)).ToList();
         foreach (var order in result)
         {
             order.OwnerName = GetCustomerString(order.OwnerId, context);
         }
         return(result);
     }
 }
Example #6
0
        public bool CheckRole(string Id, string role)
        {
            var guid = Guid.Parse(Id);

            using (var context = new DataModelDataContext())
            {
                var employee = context.Employees.FirstOrDefault(e => e.Id == guid);
                if (employee != null)
                {
                    return(context.Roles.Any(r => r.Id == employee.RoleId && r.Name == role));
                }
            }
            return(false);
        }
Example #7
0
        public void ChangeState(Guid id, string nextState, string nextStateName)
        {
            using (var context = new DataModelDataContext())
            {
                var order = Get(id, context);
                if (order == null)
                {
                    return;
                }

                order.State     = nextState;
                order.StateName = nextStateName;
                context.SubmitChanges();
            }
        }
Example #8
0
 public List <Model.OrderHistory> GetOrderHistory(Guid id)
 {
     using (var context = new DataModelDataContext())
     {
         var result = context.OrderHistories.Where(h => h.OrderId == id).OrderBy(x => x.Order).Select(h => Mappings.Mapper.Map <Model.OrderHistory>(h)).ToList();
         foreach (var history in result)
         {
             if (history.EmployeeId != null)
             {
                 history.EmployeeName = GetEmployeeString((Guid)history.EmployeeId, context);
             }
         }
         return(result);
     }
 }
Example #9
0
        private string GetCustomerString(Guid idendityGuid, DataModelDataContext context)
        {
            var customers = context.Customers.Where(e => idendityGuid == e.Id).ToList();

            var  sb      = new StringBuilder();
            bool isFirst = true;

            foreach (var customer in customers)
            {
                if (!isFirst)
                {
                    sb.Append(",");
                }
                isFirst = false;

                sb.Append(customer.Name);
            }

            return(sb.ToString());
        }
Example #10
0
        public void UpdateOrderHistory(Guid id, string currentState, string nextState, string command, Guid?employeeId)
        {
            using (var context = new DataModelDataContext())
            {
                var historyItem = new OrderHistory
                {
                    Id = Guid.NewGuid(),
                    DestinationState = nextState,
                    OrderId          = id,
                    InitialState     = currentState
                };
                context.OrderHistories.InsertOnSubmit(historyItem);

                historyItem.Command        = command;
                historyItem.TransitionTime = DateTime.Now;
                historyItem.EmployeeId     = employeeId;

                context.SubmitChanges();
            }
        }
Example #11
0
        private string GetEmployeeString(Guid idendityGuid, DataModelDataContext context)
        {
            var employees = context.Employees.Where(e => idendityGuid == e.Id).ToList();

            var  sb      = new StringBuilder();
            bool isFirst = true;

            foreach (var employee in employees)
            {
                if (!isFirst)
                {
                    sb.Append(",");
                }
                isFirst = false;

                sb.Append(employee.Name);
            }

            return(sb.ToString());
        }