コード例 #1
0
        /// <summary>
        ///     Funcion para generar un nuevo id para el registro en el historial del ticket
        /// </summary>
        /// <param name="ticketId">Id del ticket a generar un nuevo registro</param>
        /// <returns>Id del nuevo registro para el ticket</returns>
        public static int GenerateRecordId(long ticketId)
        {
            int recordNumber;

            using (var db = new dbGoldenTicket())
            {
                recordNumber = (from tblRecordAux in db.TK_DT_RECORDS
                                where tblRecordAux.TK_HD_TICKETS_ID == ticketId
                                select tblRecordAux).Distinct().Count() + 1;
            }

            return(recordNumber);
        }
コード例 #2
0
        /// <summary>
        ///     Agrega un nuevo registro en el historial de un ticket
        /// </summary>
        /// <param name="ticketRecord">Objeto con la informacion a agregar en el historial del ticket</param>
        /// <returns>TicketRegisterResult con la secuencia del nuevo registro</returns>
        public TicketRegisterResult UpdateRecord(TK_DT_RECORDS ticketRecord)
        {
            var result = new TicketRegisterResult();

            using (var db = new dbGoldenTicket())
            {
                ticketRecord.TK_DT_RECORDS_ID = GenerateRecordId(ticketRecord.TK_HD_TICKETS_ID);
                db.TK_DT_RECORDS.Add(ticketRecord);
                db.SaveChanges();

                result.SequenceNewTicket = ticketRecord.TK_DT_RECORDS_ID;
                result.Success           = true;
                result.Message           = "op_exitosa";
            }

            return(result);
        }
コード例 #3
0
        /// <summary>
        ///     Valida si un ticket le pertenece a la persona que lo esta consultando
        /// </summary>
        /// <param name="ticketId">Id del ticket a validar</param>
        /// <param name="userId">Usuario a validar</param>
        /// <returns>Booleano que indica si al usuario le pertenece el ticket</returns>
        public bool ValidateTicketOwner(long ticketId, string userId)
        {
            var result = false;

            try
            {
                using (var db = new dbGoldenTicket())
                {
                    var query = from tblTicket in db.TK_HD_TICKETS
                                join tblRecord in db.TK_DT_RECORDS on tblTicket.TK_HD_TICKETS_ID equals tblRecord
                                .TK_HD_TICKETS_ID
                                where tblTicket.TK_HD_TICKETS_ID == ticketId &&
                                tblRecord.TK_BT_EMPLOYEES_ID == userId &&
                                tblRecord.TK_DT_RECORDS_ID == (
                        from tblTicketAux in db.TK_HD_TICKETS
                        join tblRecordAux in db.TK_DT_RECORDS on tblTicketAux.TK_HD_TICKETS_ID equals
                        tblRecordAux
                        .TK_HD_TICKETS_ID
                        where tblTicket.TK_HD_TICKETS_ID == tblTicketAux.TK_HD_TICKETS_ID
                        select tblRecordAux.TK_DT_RECORDS_ID
                        ).Max()
                                select tblTicket;

                    result = query.Any();
                }
            }
            catch (DbEntityValidationException ex)
            {
                //Falló al tratar de registrar datos en la base de datos
                foreach (var e in ex.EntityValidationErrors)
                {
                    foreach (var validationError in e.ValidationErrors)
                    {
                        Console.WriteLine("Property: " + validationError.PropertyName + " Error: " +
                                          validationError.ErrorMessage);
                    }
                }
            }

            return(result);
        }
コード例 #4
0
        /// <summary>
        ///     Funcion que dados los datos de un ticket se crea un nuevo elemento
        ///     y su inicio en el historial
        /// </summary>
        /// <param name="ticketRecord">Objeto con los datos para el historial del ticket</param>
        /// <param name="ticket">objeto con los datos del ticket para su creacion </param>
        /// <returns>TicketRegisterResult con el folio y id del ticket nuevo</returns>
        public TicketRegisterResult CreateNewTicket(TK_HD_TICKETS ticket, TK_DT_RECORDS ticketRecord)
        {
            var result = new TicketRegisterResult();

            using (var db = new dbGoldenTicket())
            {
                db.TK_HD_TICKETS.Add(ticket);
                ticketRecord.TK_HD_TICKETS_ID = ticket.TK_HD_TICKETS_ID;
                ticketRecord.TK_DT_RECORDS_ID = GenerateRecordId(ticketRecord.TK_HD_TICKETS_ID);
                db.TK_DT_RECORDS.Add(ticketRecord);
                db.SaveChanges();

                result.FolioNewTicket = ticket.FOLIO;
                result.IdNewTicket    = ticket.TK_HD_TICKETS_ID;

                result.Success = true;
                result.Message = "op_exitosa";
            }

            return(result);
        }
コード例 #5
0
        /// <summary>
        ///     Funcion para generar el id del ticket
        /// </summary>
        /// <returns>Un string con el numero de ticket</returns>
        public static string GenerateTicketFolio()
        {
            string ticketNumber;

            using (var db = new dbGoldenTicket())
            {
                var count = (
                    from tblTicketAux in db.TK_HD_TICKETS
                    join tblRecordAux in db.TK_DT_RECORDS on tblTicketAux.TK_HD_TICKETS_ID equals
                    tblRecordAux.TK_HD_TICKETS_ID
                    where tblRecordAux.TK_CT_STATUS_ID == "ABT" &&
                    tblRecordAux.ACTIVITY_DATE.Year == DateTime.Today.Year &&
                    tblRecordAux.ACTIVITY_DATE.Month == DateTime.Today.Month &&
                    tblRecordAux.ACTIVITY_DATE.Day == DateTime.Today.Day
                    select tblTicketAux.TK_HD_TICKETS_ID
                    ).Distinct().Count() + 1;

                ticketNumber = DateTime.Now.ToString("yyyyMMdd") + count.ToString().PadLeft(4, '0');
            }

            return(ticketNumber);
        }