Exemplo n.º 1
0
        /**
         * Si l'utilisateur n'est pas actif : activer
         * Sinon rien faire
         */
        public Boolean ActivateUser(string token)
        {
            PublicUser user = _tokenHelper.ValidateVerificationToken(token);

            user = _context.PublicUser.First(x => x.Id == user.Id);

            if (user != null)
            {
                if (user.EstActive == false)
                {
                    user.EstActive = true;
                    try
                    {
                        _context.SaveChanges();
                        return(true);
                    }
                    catch
                    {
                    }
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        public JObject SaveDevisInformation(JObject j, string token)
        {
            dynamic          res   = new JObject();
            DevisInformation devis = null;
            //   try
            //    {
            int id = j["Devis"]["Id"].ToObject <int>();
            //Il s'agit bien d'une modification d'un devis
            var requ = j["Devis"];

            if (id != -1)
            {
                devis = _context.DevisInformation.First(d => d.Id == id);

                if (requ["nombrePoste"] != null)
                {
                    devis.NbrPoste = requ["nombrePoste"].ToObject <int>();
                }
                if (requ["nombreContrat"] != null)
                {
                    devis.NbrContrat = requ["nombreContrat"].ToObject <int>();
                }
                if (requ["logCompta"] != null)
                {
                    devis.LogCompta = requ["logCompta"].ToObject <Softwares>().Name;
                }
                if (requ["LogGestion"] != null)
                {
                    devis.LogGestion = requ["LogGestion"].ToObject <Softwares>().Name;
                }
                if (requ["lettragePart"] != null)
                {
                    devis.LettragePartiel = requ["lettragePart"].ToObject <int>();
                }
                if (requ["clotureFacture"] != null)
                {
                    devis.ClotureFacture = requ["clotureFacture"].ToObject <int>();
                }
                if (requ["preLettrage"] != null)
                {
                    devis.PreLettrage = requ["preLettrage"].ToObject <int>();
                }
                if (requ["volumetrie"] != null)
                {
                    devis.Volumetrie = requ["volumetrie"].ToObject <int>();
                }
                if (requ["mdrVRTS"] != null)
                {
                    devis.MdrPrcntVirts = requ["mdrVRTS"].ToObject <int>();
                }
                if (requ["mdrLCM"] != null)
                {
                    devis.MdrPrcntTrtSaccept = requ["mdrLCM"].ToObject <int>();
                }
                if (requ["mdrBOR"] != null)
                {
                    devis.MdrPrcntTrtAaccept = requ["mdrBOR"].ToObject <int>();
                }
                if (requ["mdrCHQ"] != null)
                {
                    devis.MdrPrcntChq = requ["mdrCHQ"].ToObject <int>();
                }
                if (requ["mdrAutre"] != null)
                {
                    devis.MdrPrcntAutres = requ["mdrAutre"].ToObject <int>();
                }



                _context.SaveChanges();
                res.saved = true;
            }
            //Il s'agit d'une nouvelle insertion d'un devis
            else
            {
                using (var transaction = _context.Database.BeginTransaction())
                {
                    int        idPublicUser = _tokenHelper.getSidToken(token);
                    PublicUser user         = _context.PublicUser.Include(u => u.Contact).Where(t => t.Id == idPublicUser).First();
                    // Console.WriteLine("PUBLIC USER ====> " + user.Username);
                    Comptes cpt = _context.CompteContact.Select(t => t.IdCptNavigation).Where(p => p.MainContactId == user.Contact.Id).FirstOrDefault();
                    Console.WriteLine("COMPTE ID ====> " + cpt.Id);

                    devis = new DevisInformation();
                    if (requ["nombrePoste"] != null)
                    {
                        devis.NbrPoste = requ["nombrePoste"].ToObject <int>();
                    }
                    if (requ["nombreContrat"] != null)
                    {
                        devis.NbrContrat = requ["nombreContrat"].ToObject <int>();
                    }
                    if (requ["logCompta"] != null)
                    {
                        devis.LogCompta = requ["logCompta"].ToObject <Softwares>().Name;
                    }
                    if (requ["LogGestion"] != null)
                    {
                        devis.LogGestion = requ["LogGestion"].ToObject <Softwares>().Name;
                    }
                    if (requ["lettragePart"] != null)
                    {
                        devis.LettragePartiel = requ["lettragePart"].ToObject <int>();
                    }
                    if (requ["clotureFacture"] != null)
                    {
                        devis.ClotureFacture = requ["clotureFacture"].ToObject <int>();
                    }
                    if (requ["preLettrage"] != null)
                    {
                        devis.PreLettrage = requ["preLettrage"].ToObject <int>();
                    }
                    if (requ["volumetrie"] != null)
                    {
                        devis.Volumetrie = requ["volumetrie"].ToObject <int>();
                    }
                    if (requ["mdrVRTS"] != null)
                    {
                        devis.MdrPrcntVirts = requ["mdrVRTS"].ToObject <int>();
                    }
                    if (requ["mdrLCM"] != null)
                    {
                        devis.MdrPrcntTrtSaccept = requ["mdrLCM"].ToObject <int>();
                    }
                    if (requ["mdrBOR"] != null)
                    {
                        devis.MdrPrcntTrtAaccept = requ["mdrBOR"].ToObject <int>();
                    }
                    if (requ["mdrCHQ"] != null)
                    {
                        devis.MdrPrcntChq = requ["mdrCHQ"].ToObject <int>();
                    }
                    if (requ["mdrAutre"] != null)
                    {
                        devis.MdrPrcntAutres = requ["mdrAutre"].ToObject <int>();
                    }



                    devis.IdCpt = cpt.Id;

                    _context.DevisInformation.Add(devis);
                    _context.SaveChanges();
                    transaction.Commit();
                    res.newId = devis.Id;
                    res.saved = true;
                }
            }
            //  }

            /*    catch (Exception e)
             *  {
             *      res.saved = false;
             *      res.error = e.Message;
             *      throw;
             *  }
             *  finally
             *  {
             *      res.time = DateTime.Now.ToString("HH:mm:ss - dd/MM/yyyy");
             *  }*/

            Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            return(res);
        }