Example #1
0
        public EmailLinkDTO GetLinks([FromQuery] string emailId)
        {
            if (!loadHandlerEmail(Request))
            {
                return(null);
            }

            EmailLinkDTO emailLink = new EmailLinkDTO();

            emailLink.emailId = emailId;

            Correu correu = _context.Correus
                            .Include("Empreses")
                            .Include("Maquines")
                            .Include("Projectes")
                            .FirstOrDefault(x => x.EmailId == emailId);

            if (correu != null)
            {
                emailLink.empresasId        = (from empresa in correu.Empreses select empresa.EmpresaId).ToList();
                emailLink.maquinesMatricula = (from maquina in correu.Maquines select maquina.Matricula).ToList();
                emailLink.projectesId       = (from projecte in correu.Projectes select projecte.ProjecteId).ToList();
            }

            return(emailLink);
        }
Example #2
0
        protected override async Task OnParametersSetAsync()
        {
            emailLink                   = new EmailLinkDTO();
            emailLink.EmpresasId        = new List <int>();
            emailLink.MaquinesMatricula = new List <string>();
            emailLink.ProjectesId       = new List <int>();

            maquinesSel  = "";
            empresesSel  = "";
            projectesSel = "";

            if (correuId != null)
            {
                try
                {
                    correu = await emailClient.GetAsync(correuId);

                    emailLink = await emailLinkClient.EmailLinkAsync(correuId);

                    maquines = await maquinesClient.MaquinesGetAsync();

                    empreses = await empresesClient.EmpresesGetAsync();

                    projectes = await projectesClient.ProjectesGetAsync();
                }
                catch (Exception ex)
                {
                    string msg = ex.Message;
                }

                js.Execute("./js/CorreoEnllac.js", "loadCorreoEnllac", DotNetObjectReference.Create(this));
            }
        }
Example #3
0
        /// <summary>
        /// Crear un nuevo CORREO con la informacion de un Email y EmalLink
        /// </summary>
        /// <param name="oEmail"></param>
        /// <param name="oEmailLink"></param>
        /// <returns></returns>
        public Correu newCorreu(EmailDTO oEmail, EmailLinkDTO oEmailLink)
        {
            Correu oCorreu = new Correu();

            getValues(ref oCorreu, ref oEmail);
            loadLinks(ref oCorreu, oEmailLink);

            return(oCorreu);
        }
Example #4
0
        public async Task <ActionResult <EmailDTO> > PostNew([FromBody] EmailSendDTO emailSend)
        {
            if (!loadHandlerEmail(Request))
            {
                return(null);
            }

            Guid guid = Guid.NewGuid();

            EmailMessage email = _handler.CrearEmail(guid, emailSend.Subject, emailSend.Body, emailSend.To, emailSend.Cc, emailSend.Bcc, emailSend.attachments);

            // Enviar correo
            if (_handler.Enviar(email))
            {
                // Recuperar el Email enviado para recuperar algunos datos.
                email = _handler.FindEmailWithGUID(guid.ToString());

                EmailLinkDTO emailLink = new EmailLinkDTO();
                emailLink.emailId           = email.Id.UniqueId;
                emailLink.empresasId        = emailSend.empresasId;
                emailLink.maquinesMatricula = emailSend.maquinesMatricula;
                emailLink.projectesId       = emailSend.projectesId;

                EmailDTO oEmail = _handler.ObtenerEmail(emailLink.emailId, true, true);
                //if (oEmail == null) return false;

                clsHandlerCorreu oHandlerCorreu = new clsHandlerCorreu(_context);
                Correu           oCorreu        = oHandlerCorreu.newCorreu(oEmail, emailLink);

                TryValidateModel(oCorreu);

                _context.Correus.Add(oCorreu);

                try
                {
                    await _context.SaveChangesAsync();

                    _handler.saveFileEmail(oEmail.emailId, oEmail.guid);
                }
                catch (Exception ex)
                {
                    string msg = ex.Message;
                }


                return(CreatedAtAction("GetEmaiId", new { id = email.Id.UniqueId }, oEmail));
            }
            else
            {
                return(NoContent());
            }
        }
Example #5
0
        public async Task <ActionResult <EmailDTO> > Put([FromQuery] int id, [FromBody] EmailLinkDTO emailLink)
        {
            if (!loadHandlerEmail(Request))
            {
                return(null);
            }

            Correu oCorreu = await _context.Correus
                             .Include(x => x.Empreses)
                             .Include(x => x.Maquines)
                             .Include(x => x.Projectes)
                             .FirstOrDefaultAsync(x => x.CorreuId == id);

            //.FindAsync(id);

            if (oCorreu == null)
            {
                return(NotFound());
            }
            //if (oCorreu.MissatgeId != oEmailLink.emailId) return BadRequest(); // TO DO Que comparas?

            clsHandlerCorreu oHandlerCorreu = new clsHandlerCorreu(_context);

            oHandlerCorreu.modCorreu(ref oCorreu, emailLink);

            _context.Entry(oCorreu).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CorreuExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #6
0
        /// <summary>
        /// Cargar enlaces de un EmailLink a un objecto CORREO
        /// </summary>
        /// <param name="oCorreu">Correo destino</param>
        /// <param name="oEmailLink">EmailLink origen</param>
        public void loadLinks(ref Correu oCorreu, EmailLinkDTO oEmailLink)
        {
            oCorreu.Empreses = new List <Empresa>();
            if (oEmailLink.empresasId != null)
            {
                oCorreu.Empreses = _context.Empreses.Where(x => oEmailLink.empresasId.Contains(x.EmpresaId)).ToList();
            }

            oCorreu.Maquines = new List <Maquina>();
            if (oEmailLink.maquinesMatricula != null)
            {
                oCorreu.Maquines = _context.Maquines.Where(x => oEmailLink.maquinesMatricula.Contains(x.Matricula)).ToList();
            }

            oCorreu.Projectes = new List <Projecte>();
            if (oEmailLink.projectesId != null)
            {
                oCorreu.Projectes = _context.Projectes.Where(x => oEmailLink.projectesId.Contains(x.ProjecteId)).ToList();
            }
        }
Example #7
0
        public async Task <ActionResult <EmailDTO> > Post([FromQuery] string id, [FromBody] EmailLinkDTO emailLink)//, [FromBody] EmailDTO email)
        {
            if (!loadHandlerEmail(Request))
            {
                return(null);
            }

            if (id != emailLink.emailId)
            {
                return(BadRequest());
            }

            EmailDTO oEmail = _handler.ObtenerEmail(emailLink.emailId, true, true);
            //if (oEmail == null) return false;

            clsHandlerCorreu oHandlerCorreu = new clsHandlerCorreu(_context);
            Correu           oCorreu        = oHandlerCorreu.newCorreu(oEmail, emailLink);

            TryValidateModel(oCorreu);

            _context.Correus.Add(oCorreu);

            try
            {
                await _context.SaveChangesAsync();

                // TO DO Guardar el correo
                _handler.saveFileEmail(oEmail.emailId, oEmail.guid);
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
            }

            return(CreatedAtAction("GetEmaiId", new { id = id }, oEmail)); //email);
        }
Example #8
0
 /// <summary>
 /// Modificar enlaces de un CORREO
 /// </summary>
 /// <param name="oCorreu">Correo a modificar</param>
 /// <param name="oEmailLink">Enlaces a modificar</param>
 public void modCorreu(ref Correu oCorreu, EmailLinkDTO oEmailLink)
 {
     loadLinks(ref oCorreu, oEmailLink);
 }