Exemplo n.º 1
0
        public string GenerateCode(int pUserId)
        {
            string code = string.Empty;
            bool   ok   = false;

            while (!ok)
            {
                int  longitud = 10;
                Guid miGuid   = Guid.NewGuid();
                code = Convert.ToBase64String(miGuid.ToByteArray());
                code = code.Replace("=", "").Replace("+", "");
                code = code.Substring(0, longitud);

                using (SEDESOLEntities db = new SEDESOLEntities())
                {
                    INSPECTION_CODE insCode = db.INSPECTION_CODE.FirstOrDefault(v => v.InspectionCode == code && v.Id_User == pUserId);
                    if (insCode != null)
                    {
                        ok = false;
                    }
                    else
                    {
                        ok = true;
                        break;
                    }
                }
            }


            return(code);
        }
Exemplo n.º 2
0
        public InspectionCodeDTO Save(InspectionCodeDTO dto)
        {
            try
            {
                using (SEDESOLEntities db = new SEDESOLEntities())
                {
                    INSPECTION_CODE insCode = db.INSPECTION_CODE.FirstOrDefault(v => v.InspectionCode == dto.InspectionCode && v.Id_User == dto.Id_User);
                    if (insCode != null)
                    {
                        dto.Message = "Se ha ingresado previamente el código generado.";
                    }
                    else
                    {
                        INSPECTION_CODE insCode2 = db.INSPECTION_CODE.FirstOrDefault(v => v.Id_Year == dto.Id_Year && v.Id_Month == dto.Id_Month && v.Id_User == dto.Id_User);
                        if (insCode2 != null)
                        {
                            dto.Message = "Se ha generado previamente un código para el año y mes seleccionados.";
                        }
                        else
                        {
                            GEN_CODE_DAY genCode = db.GEN_CODE_DAY.FirstOrDefault(x => x.Id_Month == dto.Id_Month && x.Id_Year == dto.Id_Year);
                            if (genCode == null)
                            {
                                dto.Message = "No se ha habilitado la generación de códigos para el mes y año seleccionados.";
                            }
                            else
                            {
                                DateTime dateToValidate = new DateTime(Convert.ToInt32(genCode.YEAR.Description), genCode.Id_Month, genCode.Day);

                                if (DateTime.Today < dateToValidate)
                                {
                                    dto.Message = "No se ha habilitado la generación de códigos para el mes y año seleccionados.";
                                }
                                else
                                {
                                    INSPECTION_CODE insEntity = new INSPECTION_CODE
                                    {
                                        Id_Month       = dto.Id_Month,
                                        Id_Year        = dto.Id_Year,
                                        Id_User        = dto.Id_User,
                                        InspectionCode = dto.InspectionCode
                                    };

                                    db.INSPECTION_CODE.Add(insEntity);
                                    if (db.SaveChanges() > 0)
                                    {
                                        dto.Id      = insEntity.Id;
                                        dto.Message = "SUCCESS";
                                    }
                                    else
                                    {
                                        dto.Message = "Se ha producido un error al guardar el código de inspección";
                                    }
                                }
                            }
                        }
                    }
                    return(dto);
                }
            }
            catch (Exception ex)
            {
                return(new InspectionCodeDTO());
            }
        }
Exemplo n.º 3
0
        public CaptureDTO Save(CaptureDTO capture)
        {
            try
            {
                using (SEDESOLEntities db = new SEDESOLEntities())
                {
                    CAPTURE cap = db.CAPTUREs.FirstOrDefault(v => v.Id_Year == capture.Id_Year && v.Id_Month == capture.Id_Month && v.Id_SoupKitchen == capture.Id_Soup_Kitchen && capture.IsActive == true);
                    if (cap != null)
                    {
                        capture.Message = "Se ha creado previamente una captura para el periodo seleccionado.";
                    }
                    else
                    {
                        INSPECTION_CODE code = db.INSPECTION_CODE.FirstOrDefault(v => v.Id_Year == capture.Id_Year && v.Id_Month == capture.Id_Month && v.InspectionCode == capture.InspectionCode);
                        if (code == null)
                        {
                            capture.Message = "El Código de inspección ingresado es incorrecto";
                        }
                        else
                        {
                            CAPTURE captureEntity = new CAPTURE
                            {
                                Description      = capture.Description,
                                CreateDate       = capture.CreateDate,
                                IsActive         = capture.IsActive,
                                Id_Month         = capture.Id_Month,
                                Id_Year          = capture.Id_Year,
                                Id_Status        = capture.Id_Status,
                                Id_SoupKitchen   = (int)capture.Id_Soup_Kitchen,
                                Folio            = capture.Folio,
                                InspectionCode   = capture.InspectionCode,
                                Id_LevelApproval = capture.Id_LevelApproval,
                                Id_User          = capture.Id_User
                            };

                            db.CAPTUREs.Add(captureEntity);
                            if (db.SaveChanges() > 0)
                            {
                                capture.Id      = captureEntity.Id;
                                capture.Message = "SUCCESS";

                                //var query = from st in db.STATUS
                                //            where st.Id == capture.Id_Status
                                //            select new StatusDTO
                                //            {
                                //                Id = captureEntity.STATUS.Id,
                                //                Description = captureEntity.STATUS.Description,
                                //                IsActive = captureEntity.STATUS.IsActive
                                //            };
                                //capture.Status = query.FirstOrDefault();
                            }
                            else
                            {
                                return(new CaptureDTO());
                            }
                        }
                    }
                    return(capture);
                }
            }
            catch (Exception ex)
            {
                return(new CaptureDTO());
            }
        }