Exemplo n.º 1
0
        private void OnSubmit(object parameter)
        {
            try
            {
                var deviceObj = new tblDeviceDetails();
                deviceObj.id            = ID;
                deviceObj.location      = Location;
                deviceObj.type          = Type;
                deviceObj.device_health = Device_Health;
                deviceObj.last_used     = Last_Used.Date;
                deviceObj.price         = Convert.ToDecimal(Price);
                deviceObj.color         = Color;


                using (var db = new DeviceInfoManagerEntities())
                {
                    db.tblDeviceDetails.Add(deviceObj);
                    db.SaveChanges();
                }

                MessageBox.Show("Device details successfully added!");
                _mainVMCallback.LoadDeviceDetails();
            }

            catch (Exception ex)
            {
                MessageBox.Show("Unexpected error occured. \n" + ex.InnerException);
            }
        }
        public EditDeviceViewModel(tblDeviceDetails deviceObj, IMainViewModelCallback mainVM)
        {
            _deviceObj      = deviceObj;
            _mainVMCallback = mainVM;

            SubmitCommand = new DelegateCommand(OnSubmit, OnCanSubmit);
            RevertCommand = new DelegateCommand(OnRevert, OnCanRevert);

            if (deviceObj != null)
            {
                ID            = deviceObj.id;
                Location      = deviceObj.location;
                Device_Health = deviceObj.device_health;
                Type          = deviceObj.type;
                Price         = Convert.ToDouble(deviceObj.price);
                Last_Used     = Convert.ToDateTime(deviceObj.last_used).Date;
                Color         = deviceObj.color;
            }
            else
            {
                //Implement defaults or fetch current selected item
            }
        }