public bool UpdateTicket(TicketHistoryViewModel baseTicket, string ticketIdLocal)
        {
            var entityTicketId = _searchQueriesService.SearchTicketId(ticketIdLocal);

            if (!UpdateTicketStatus(baseTicket.idStatus, entityTicketId))
            {
                return(false);
            }

            _database = new dbSIACEntities();
            var updateTicket = new ticketHistory
            {
                date     = DateTime.Now,
                idPeople = baseTicket.idPeople,
                idStatus = baseTicket.idStatus,
                idTicket = entityTicketId,
                note     = baseTicket.note
            };

            try
            {
                using (_database)
                {
                    _database.ticketHistory.Add(updateTicket);
                    _database.SaveChanges();
                }
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
        public bool EditTicket(TicketViewModel baseTicket, string ticketId)
        {
            if (!int.TryParse(ticketId, out var currentTicketId))
            {
                return(false);
            }

            _database = new dbSIACEntities();
            using (_database)
            {
                var result = _database.ticket.FirstOrDefault(b => b.idLocal == currentTicketId);
                if (result == null)
                {
                    _database.Dispose();
                    return(false);
                }

                result.idCategory           = baseTicket.idCategory;
                result.idAssignedTechnician = baseTicket.idAssignedTechnician;
                result.idPriority           = baseTicket.idPriority;
                result.idStatus             = baseTicket.idStatus;
                result.description          = baseTicket.description;
                _database.SaveChanges();
            }

            return(true);
        }
        public bool UpdateTicketStatus(int idStatus, int ticketId)
        {
            if (ticketId <= 0)
            {
                return(false);
            }

            _database = new dbSIACEntities();
            using (_database)
            {
                var ticketDefault = _database.ticket.FirstOrDefault(ticket => ticket.id == ticketId);
                if (ticketDefault == null)
                {
                    return(false);
                }

                ticketDefault.idStatus    = idStatus;
                ticketDefault.editionDate = DateTime.Now;
                try
                {
                    _database.ticket.AddOrUpdate(ticketDefault);
                    _database.SaveChanges();
                }
                catch (Exception)
                {
                    return(false);
                }

                return(true);
            }
        }
        /// <summary>
        ///     Include in the view model only the properties you want to update. After the MVC model linker is finished,
        ///     copy the properties of the view model into the entity instance and use the tool as an automapper.
        /// </summary>
        /// <param name="registrationViewModel"></param>
        /// <returns>True all good, False something goes wrong </returns>
        public bool CreatePeople(RegistrationViewModel registrationViewModel)
        {
            _database = new dbSIACEntities();
            var peopleCount = _database.people.Count();

            using (_database)
            {
                var newPeople = new people
                {
                    creationDate = DateTime.Now,
                    address      = registrationViewModel.address,
                    dni          = registrationViewModel.dni,
                    name         = registrationViewModel.name,
                    lastname     = registrationViewModel.lastname,
                    email        = registrationViewModel.email,
                    pass         = Encrypt.GetSHA256(registrationViewModel.pass),
                    idRol        = registrationViewModel.idRol,
                    isActive     = 1
                };
                _database.people.Add(newPeople);
                _database.SaveChanges();

                if (peopleCount == _database.people.Count())
                {
                    return(false);
                }
                return(true);
            }
        }
        /// <summary>
        ///     Create a new ticket, if a client is the creator idClient is taken from the sessionUser info. Othewise from the
        ///     ViewModel.
        /// </summary>
        /// <param name="baseTicket"></param>
        /// <param name="sessionUser"></param>
        /// <returns>True ticket created. False something went wrong</returns>
        public (bool result, int idLocal) CreateTicket(TicketViewModel baseTicket, people sessionUser)
        {
            var random = new Random();

            baseTicket.idLocal = random.Next(1000, 99999); //Algun dia llegara a mas de esa cantidad de tickets?

            _database = new dbSIACEntities();
            if (baseTicket.idClient == 0)
            {
                baseTicket.idClient = sessionUser.id;
            }
            if (baseTicket.idAssignedTechnician == null)
            {
                baseTicket.idAssignedTechnician = 1;
            }

            var ticket = new ticket
            {
                idLocal              = baseTicket.idLocal,
                idStatus             = baseTicket.idStatus,
                idCreatorPeople      = sessionUser.id,
                creationDate         = baseTicket.creationDate,
                estimatedFinishDate  = baseTicket.estimatedFinishDate,
                idPriority           = baseTicket.idPriority,
                idCategory           = baseTicket.idCategory,
                description          = baseTicket.description,
                idClient             = baseTicket.idClient,
                idAssignedTechnician = baseTicket.idAssignedTechnician
            };

            try
            {
                using (_database)
                {
                    _database.ticket.Add(ticket);
                    _database.SaveChanges();
                }

                return(true, baseTicket.idLocal);
            }
            catch (Exception)
            {
                return(false, 0);
            }
        }