public CaseWindow(Cases pCase)
        {
            InitializeComponent();
            ModelContainerHolder.UpdateModel();
            m_case = pCase;
            ModelContainerHolder.Model.Cases.Attach(m_case);
            this.Title = pCase.Id.ToString() + " - " + pCase.Customer.Name;
            InitBindings();


        }
示例#2
0
        //Function should be placed on Cases
        public static int NewCase(string customerNumber, int ownerId, DateTime time)
        {
            try
            {
                Customers customer = Model.Customers.Where(a => a.PhoneNumber == customerNumber).FirstOrDefault();
                Users     owner    = Model.Users.Find(ownerId);
                if (customer == null)
                {
                    //Make new "Okänd kund" with customerNumber and make it possible to change user if unkown. also add feature to unlock and edit customer on case.
                    //throw new Exception("Customer not found"); //Should notify pcuser and create new customer
                    int customerId = NewCustomer(customerNumber);
                    customer = Model.Customers.Find(customerId);
                }

                if (owner != null)
                {
                    try
                    {
                        Cases entity = Model.Cases.Add(new Cases()
                        {
                            Owner = owner, Customer = customer, StartTime = time
                        });
                        Model.SaveChanges();
                        return(entity.Id);
                    }
                    catch (InvalidCastException e)
                    {
                    }
                    catch (Exception e)
                    {
                    }
                }
                else
                {
                    throw new Exception("Owner not found");
                }
            }
            catch (Exception e)
            {
                //Error..
            }



            return(-1);
        }
 private void DeleteCase(Cases pCase)
 {
     pCase.Active = false;
     model.Model.SaveChanges();
     UpdateCases();
 }
 public void OpenCaseWindow(Cases Case)
 {
    
     CaseWindow cw = new CaseWindow(Case);
     cw.Show();
 }