public void Receive()
        {
            var receivedThermostat = new ReceivedThermostat
            {
                ReceivingEmployee       = String.Format("{0} {1}", EmployeeViewModel.SelectedEmployee.FirstName, EmployeeViewModel.SelectedEmployee.LastName),
                ThermostatId            = context.GetId(BarcodeNumber),
                ReceivedDate            = ReceivedDate,
                ActivityPerformed       = ActivityPerformed,
                DescriptionIntervention = DescriptionIntervention,
                LastLocation            = LastLocation
            };

            if (!context.IsAccepted(BarcodeNumber))
            {
                context.Receive(receivedThermostat);
            }
            else
            {
                context.UpdateOnReceive(receivedThermostat);
            }

            if (receivedThermostat.ActivityPerformed == "Awaria")
            {
                context.SetCurrentStatus(receivedThermostat, "Awaria");
            }
            else
            {
                context.SetCurrentStatus(receivedThermostat, "W czasie: " + receivedThermostat.ActivityPerformed.ToString());
            }

            context.SetCurrentLocation(receivedThermostat, "Warsztat");

            ConnectedSuccessfully = true;
        }
        public void Receive(ReceivedThermostat receivedThermostat)
        {
            Validator.RequireString(receivedThermostat.ReceivingEmployee);
            Validator.RequireString(receivedThermostat.ActivityPerformed);

            context.ReceivedThermostats.Add(receivedThermostat);
            context.SaveChanges();
        }
        public void SetCurrentStatus(ReceivedThermostat receivedThermostat, string currentStatus)
        {
            var t = (from c in context.Thermostats
                     where c.Id == receivedThermostat.ThermostatId
                     select c).First();

            t.CurrentStatus = currentStatus;

            context.SaveChanges();
        }
        public void SetLastWashDate(ReceivedThermostat receivedThermostat)
        {
            if (receivedThermostat.ActivityPerformed == "Plukanie termostatu" || receivedThermostat.ActivityPerformed == "Awaria")
            {
                var t =
                    (from c in context.Thermostats
                     where c.Id == receivedThermostat.ThermostatId
                     select c).First();
                t.LastWashDate = DateTime.Now;

                context.SaveChanges();
            }
        }
        public void SetLastPreventionDate(ReceivedThermostat receivedThermostat)
        {
            if (receivedThermostat.ActivityPerformed == "Prewencja")
            {
                var t =
                    (from c in context.Thermostats
                     where c.Id == receivedThermostat.ThermostatId
                     select c).First();
                t.LastPreventionDate = DateTime.Now;

                context.SaveChanges();
            }
        }
        public void UpdateOnReceive(ReceivedThermostat receivedThermostat)
        {
            var entity = context.ReceivedThermostats
                         .Where(c => c.ThermostatId == receivedThermostat.ThermostatId)
                         .FirstOrDefault();

            receivedThermostat.Id = entity.Id;
            if (entity != null)
            {
                context.Entry(entity).CurrentValues.SetValues(receivedThermostat);
                context.SaveChanges();
            }
        }
        public void Spend()
        {
            var spendedThermostat = new SpendedThermostat
            {
                ThermostatId            = SelectedReceivedThermostat.ThermostatId,
                ReceivedDate            = SelectedReceivedThermostat.ReceivedDate,
                ActivityPerformed       = SelectedReceivedThermostat.ActivityPerformed,
                RepairDate              = RepairDate,
                DescriptionIntervention = SelectedReceivedThermostat.DescriptionIntervention,
                LastLocation            = SelectedReceivedThermostat.LastLocation,
                ReceivingEmployee       = SelectedReceivedThermostat.ReceivingEmployee,
                SpendingEmployee        = String.Format("{0} {1}", EmployeeViewModel.SelectedEmployee.FirstName, EmployeeViewModel.SelectedEmployee.LastName)
            };

            context.SetLastPreventionDate(SelectedReceivedThermostat);
            context.SetLastWashDate(SelectedReceivedThermostat);
            context.SetCurrentLocation(SelectedReceivedThermostat, CurrentLocation);
            context.SetCurrentStatus(SelectedReceivedThermostat, "Sprawny");

            if (CurrentLocation != "Warsztat") //If the release on the machine it seems
            {
                context.Spend(spendedThermostat);

                if (SelectedReceivedThermostat != null)
                {
                    context.Remove(SelectedReceivedThermostat);
                    ReceivedThermostats.Remove(SelectedReceivedThermostat);
                    SelectedReceivedThermostat = null;
                }
            }
            else  //If the relese for the workshop take back
            {
                var receivedThermostat = new ReceivedThermostat
                {
                    ThermostatId            = SelectedReceivedThermostat.ThermostatId,
                    ReceivedDate            = SelectedReceivedThermostat.ReceivedDate,
                    ActivityPerformed       = "Do wydania",
                    DescriptionIntervention = null,
                    LastLocation            = SelectedReceivedThermostat.LastLocation,
                    ReceivingEmployee       = SelectedReceivedThermostat.ReceivingEmployee
                };

                context.UpdateOnSpend(receivedThermostat);
                context.Spend(spendedThermostat);
            }

            ConnectedSuccessfully = true;
        }
 public void Remove(ReceivedThermostat receivedThermostat)
 {
     context.ReceivedThermostats.Remove(receivedThermostat);
     context.SaveChanges();
 }