public async Task <IActionResult> Index(ManageMessageId?message = null)
        {
            ViewData["StatusMessage"] =
                message == ManageMessageId.ChangePasswordSuccess ? "Votre mot de passe a été modifié avec succès."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Votre numero de telephone a été enregistré avec succès."
                : message == ManageMessageId.RemovePhoneSuccess ? "Votre numero de telephone a été supprimé avec succès."
                : "";

            var user = await GetCurrentUserAsync();

            var model = new IndexViewModel
            {
                HasPassword       = await _userManager.HasPasswordAsync(user),
                PhoneNumber       = await _userManager.GetPhoneNumberAsync(user),
                TwoFactor         = await _userManager.GetTwoFactorEnabledAsync(user),
                Logins            = await _userManager.GetLoginsAsync(user),
                BrowserRemembered = await _signInManager.IsTwoFactorClientRememberedAsync(user)
            };

            currentUser             = _dbContext.Users.Where(c => c.Id == HttpContext.User.GetUserId()).FirstOrDefault();
            ViewBag.Compte          = currentUser.CompteUnite;
            compte                  = _dbContext.Comptes.Where(c => c.Id == "1").FirstOrDefault();
            ViewBag.ComptePrincipal = compte.SoldeUnite;
            return(View(model));
        }
        public async Task <IActionResult> SetPassword(SetPasswordViewModel model)
        {
            var user = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                currentUser             = _dbContext.Users.Where(c => c.Id == HttpContext.User.GetUserId()).FirstOrDefault();
                ViewBag.Compte          = currentUser.CompteUnite;
                compte                  = _dbContext.Comptes.Where(c => c.Id == "1").FirstOrDefault();
                ViewBag.ComptePrincipal = compte.SoldeUnite;
                return(View(model));
            }

            if (user != null)
            {
                var result = await _userManager.AddPasswordAsync(user, model.NewPassword);

                if (result.Succeeded)
                {
                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(RedirectToAction(nameof(Index), new { Message = ManageMessageId.SetPasswordSuccess }));
                }
                AddErrors(result);

                currentUser             = _dbContext.Users.Where(c => c.Id == HttpContext.User.GetUserId()).FirstOrDefault();
                ViewBag.Compte          = currentUser.CompteUnite;
                compte                  = _dbContext.Comptes.Where(c => c.Id == "1").FirstOrDefault();
                ViewBag.ComptePrincipal = compte.SoldeUnite;
                return(View(model));
            }
            return(RedirectToAction(nameof(Index), new { Message = ManageMessageId.Error }));
        }
        public async Task <IActionResult> ManageLogins(ManageMessageId?message = null)
        {
            ViewData["StatusMessage"] =
                message == ManageMessageId.RemoveLoginSuccess ? "The external login was removed."
                : message == ManageMessageId.AddLoginSuccess ? "The external login was added."
                : message == ManageMessageId.Error ? "An error has occurred."
                : "";
            var user = await GetCurrentUserAsync();

            if (user == null)
            {
                currentUser             = _dbContext.Users.Where(c => c.Id == HttpContext.User.GetUserId()).FirstOrDefault();
                ViewBag.Compte          = currentUser.CompteUnite;
                compte                  = _dbContext.Comptes.Where(c => c.Id == "1").FirstOrDefault();
                ViewBag.ComptePrincipal = compte.SoldeUnite;
                return(View("Error"));
            }
            var userLogins = await _userManager.GetLoginsAsync(user);

            var otherLogins = _signInManager.GetExternalAuthenticationSchemes().Where(auth => userLogins.All(ul => auth.AuthenticationScheme != ul.LoginProvider)).ToList();

            ViewData["ShowRemoveButton"] = user.PasswordHash != null || userLogins.Count > 1;

            currentUser             = _dbContext.Users.Where(c => c.Id == HttpContext.User.GetUserId()).FirstOrDefault();
            ViewBag.Compte          = currentUser.CompteUnite;
            compte                  = _dbContext.Comptes.Where(c => c.Id == "1").FirstOrDefault();
            ViewBag.ComptePrincipal = compte.SoldeUnite;
            return(View(new ManageLoginsViewModel
            {
                CurrentLogins = userLogins,
                OtherLogins = otherLogins
            }));
        }
Пример #4
0
        public IActionResult CreerNouveauRechargement(RechargeCptePrincTrace rcompteprincipal)
        {
            if (ModelState.IsValid)
            {
                rcompteprincipal.Id = Guid.NewGuid().ToString();
                rcompteprincipal.DateTransaction = DateTime.UtcNow;
                rcompteprincipal.Benef           = rcompteprincipal.Montant * (0.03);
                rcompteprincipal.Etat            = "ACTIF";
                rcompteprincipal.Montant         = rcompteprincipal.Montant + rcompteprincipal.Benef;
                ApplicationUser currentUser1 = _context.Users.Where(c => c.Id == HttpContext.User.GetUserId()).FirstOrDefault();

                rcompteprincipal.useremail = currentUser1.Email;
                _context.RechargeCptePrincTrace.Add(rcompteprincipal);


                //mise a jour du solde principal a chaque rechargement
                Comptes compte = new Comptes();
                compte             = _context.Comptes.Where(c => c.Id == "1").FirstOrDefault();
                compte.SoldeUnite += rcompteprincipal.Montant;
                _context.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(rcompteprincipal));
        }
Пример #5
0
        public IHttpActionResult PutComptes(string id, Comptes comptes)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != comptes.Numero)
            {
                return(BadRequest());
            }

            db.Entry(comptes).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ComptesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #6
0
        public IHttpActionResult PostComptes(Comptes comptes)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Comptes.Add(comptes);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (ComptesExists(comptes.Numero))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = comptes.Numero }, comptes));
        }
        public async Task <IActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model)
        {
            if (!ModelState.IsValid)
            {
                currentUser    = _dbContext.Users.Where(c => c.Id == HttpContext.User.GetUserId()).FirstOrDefault();
                ViewBag.Compte = currentUser.CompteUnite;
                return(View(model));
            }
            var user = await GetCurrentUserAsync();

            if (user != null)
            {
                var result = await _userManager.ChangePhoneNumberAsync(user, model.PhoneNumber, model.Code);

                if (result.Succeeded)
                {
                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(RedirectToAction(nameof(Index), new { Message = ManageMessageId.AddPhoneSuccess }));
                }
            }
            // If we got this far, something failed, redisplay the form
            ModelState.AddModelError(string.Empty, "Failed to verify phone number");

            currentUser             = _dbContext.Users.Where(c => c.Id == HttpContext.User.GetUserId()).FirstOrDefault();
            ViewBag.Compte          = currentUser.CompteUnite;
            compte                  = _dbContext.Comptes.Where(c => c.Id == "1").FirstOrDefault();
            ViewBag.ComptePrincipal = compte.SoldeUnite;
            return(View(model));
        }
Пример #8
0
        public ActionResult DeleteConfirmed(int id)
        {
            Comptes comptes = db.Comptes.Find(id);

            db.Comptes.Remove(comptes);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        private void EventFrmNouveauCompteClick(object sender, EventArgs e)
        {
            Comptes listeCompte = new Comptes();

            listeCompte.Load(Settings.Default.BanqueAppData);
            FrmNouveauCompte fNC  = new FrmNouveauCompte(listeCompte);
            DialogResult     dial = fNC.ShowDialog();
        }
Пример #10
0
 public TCompte this[int index]
 {
     get
     {
         return(Comptes.Find(cpt => cpt.Numero == index));
         //return Comptes.Where(cpt => cpt.Numero == index).Select(cpt => cpt).FirstOrDefault();
     }
 }
Пример #11
0
        public IActionResult DeleteConfirmed(string id)
        {
            Comptes comptes = _context.Comptes.Single(m => m.Id == id);

            _context.Comptes.Remove(comptes);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public IActionResult SetPassword()
 {
     currentUser             = _dbContext.Users.Where(c => c.Id == HttpContext.User.GetUserId()).FirstOrDefault();
     ViewBag.Compte          = currentUser.CompteUnite;
     compte                  = _dbContext.Comptes.Where(c => c.Id == "1").FirstOrDefault();
     ViewBag.ComptePrincipal = compte.SoldeUnite;
     return(View());
 }
Пример #13
0
        // GET: Comptes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Comptes comptes = db.Comptes.Find(id);

            List <SelectListItem> Stat = new List <SelectListItem>();

            foreach (var item in db.StatutsComptes.ToList())
            {
                if (comptes.idRoles == item.Id)
                {
                    Stat.Add(new SelectListItem()
                    {
                        Text = item.Libelle, Value = item.Id.ToString(), Selected = true
                    });
                }
                else
                {
                    Stat.Add(new SelectListItem()
                    {
                        Text = item.Libelle, Value = item.Id.ToString()
                    });
                }
            }
            ViewData["idStatutsComptes"] = Stat;

            List <SelectListItem> Rol = new List <SelectListItem>();

            foreach (var item in db.Roles.ToList())
            {
                if (comptes.idStatutsComptes == item.Id)
                {
                    Rol.Add(new SelectListItem()
                    {
                        Text = item.Libelle, Value = item.Id.ToString(), Selected = true
                    });
                }
                else
                {
                    Rol.Add(new SelectListItem()
                    {
                        Text = item.Libelle, Value = item.Id.ToString()
                    });
                }
            }
            ViewData["idRoles"] = Rol;

            if (comptes == null)
            {
                return(HttpNotFound());
            }
            return(View(comptes));
        }
Пример #14
0
 public IActionResult Edit(Comptes comptes)
 {
     if (ModelState.IsValid)
     {
         _context.Update(comptes);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(comptes));
 }
Пример #15
0
        public void SynchroniserComptes()
        {
            Comptes.Clear();

            string path = "Compte/Client/" + IdClient;

            foreach (Compte compte in _restApiQueries.GetComptes(path))
            {
                Comptes.Add(compte);
            }
        }
Пример #16
0
        public IHttpActionResult GetComptes(string id)
        {
            Comptes comptes = db.Comptes.Find(id);

            if (comptes == null)
            {
                return(NotFound());
            }

            return(Ok(comptes));
        }
Пример #17
0
        private void AddCompte()
        {
            if (Comptes.Any(c => c.NomCompte == _addedCompte.NomCompte))
            {
                MessageBox.Show("Le compte existe déjà", "Erreur", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                int nbComptes = DBContext.Comptes.Count();


                Models.Compte compteToAdd = new Models.Compte()
                {
                    //CompteId = nbComptes+2, // Oon doit trouver tout les comptes pour affecter le bon id au niveau du modèle (+2 parce qu'il ne faut incrémenter (+1) et que ça ne commence pas à 0 (+1)
                    ClientId     = this.Client.Id,
                    DateCreation = System.DateTime.Now,
                    NomCompte    = this._addedCompte.NomCompte
                };

                //MessageBox.Show("CompteId à affecter :" + (nbComptes + 2));
                DBContext.Add(compteToAdd);
                DBContext.SaveChanges();



                Models.Panier panierToAdd = new Models.Panier()
                {
                    Compte = compteToAdd
                };
                DBContext.Add(panierToAdd);
                DBContext.SaveChanges();


                OpenListeCompteClient(Client);

                /*compteToAdd.CompteId = nbComptes + 2;
                 * this.Comptes.Add(compteToAdd);*/



                // On ne peut pas ajouter le Compte au Client dans le modèle vu qu'on se balade avec un Utilisateur et pas un client à cause de ce satané Table per Type

                /*DBContext.Comptes.Add(new Models.Compte()
                 * {
                 *  ClientId = this.Client.Id,
                 *  DateCreation = System.DateTime.Now,
                 *  NomCompte = this._addedCompte.NomCompte
                 * });
                 * DBContext.SaveChanges();*/

                //MessageBox.Show("Le compte " + _addedCompte.NomCompte + " a été ajouté");
            }
        }
Пример #18
0
        public ActionResult Create([Bind(Include = "Id,Nom,Prenom,Login,Password,Mail,Tel,Adresse,CodePostal,Ville")] Comptes comptes)
        {
            if (ModelState.IsValid)
            {
                comptes.idRoles          = 2;
                comptes.idStatutsComptes = 1;
                db.Comptes.Add(comptes);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(comptes));
        }
Пример #19
0
        public AdminController(ApplicationDbContext context)
        {
            _context = context;
            total    = _context.Users.Count();
            compte   = _context.Comptes.Where(c => c.Id == "1").FirstOrDefault();
            solde    = compte.SoldeUnite;
            benef    = _context.RechargeCptePrincTrace.Sum(s => s.Benef);
            //GetListAdmin("ADMIN");

            moisTran         = DateTime.UtcNow.Month;
            smoisTran        = DateTime.UtcNow.ToString("MMMM");
            anneeTran        = DateTime.UtcNow.Year;
            benefTransaction = _context.Transactions.Where(c => c.DateTransaction.Month == moisTran && c.status.ToUpper().Equals("TERMINER")).Sum(s => (s.Montant * (s.Pourcentage + 3)) / 100);
        }
Пример #20
0
        public IHttpActionResult DeleteComptes(string id)
        {
            Comptes comptes = db.Comptes.Find(id);

            if (comptes == null)
            {
                return(NotFound());
            }

            db.Comptes.Remove(comptes);
            db.SaveChanges();

            return(Ok(comptes));
        }
Пример #21
0
        // GET: Comptes/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Comptes comptes = db.Comptes.Find(id);

            if (comptes == null)
            {
                return(HttpNotFound());
            }
            return(View(comptes));
        }
Пример #22
0
        public ActionResult Edit([Bind(Include = "Id,Nom,Prenom,Login,Password,Mail,Tel,Adresse,CodePostal,Ville,idStatutsComptes,idRoles")] Comptes comptes)
        {
            if (ModelState.IsValid)
            {
                comptes.Role = db.Roles.Where(x => x.Id == comptes.idRoles).First();

                comptes.StatutCompte = db.StatutsComptes.Where(x => x.Id == comptes.idStatutsComptes).First();


                db.Entry(comptes).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(comptes));
        }
Пример #23
0
        public Object updateCompte(Comptes c)
        {
            try
            {
                using (var transaction = _context.Database.BeginTransaction())
                {
                    _context.Comptes.Update(c);
                    transaction.Commit();
                }
            }
            catch (DbUpdateException)
            {
            }

            return(null);
        }
Пример #24
0
        public IActionResult Delete(string id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            Comptes comptes = _context.Comptes.Single(m => m.Id == id);

            if (comptes == null)
            {
                return(HttpNotFound());
            }

            return(View(comptes));
        }
Пример #25
0
        private static void CreerComptes()
        {
            Comptes comptes = new Comptes();
            Compte  compte  = new Compte
            {
                CodeClient    = "23456754",
                CodeBanque    = "20041",
                CodeGuichet   = "01006",
                Numero        = "0068875R027",
                CleRIB        = "70",
                LibelleCompte = "Mickaël Barrer Banque Postale"
            };

            comptes.Add(compte);
            compte = new Compte
            {
                CodeClient    = "23456754",
                CodeBanque    = "10907",
                CodeGuichet   = "00237",
                Numero        = "44219104266",
                CleRIB        = "03",
                LibelleCompte = "Bost Banque Populaire courant"
            };
            comptes.Add(compte);
            compte = new Compte
            {
                CodeClient    = "23456754",
                CodeBanque    = "10907",
                CodeGuichet   = "00237",
                Numero        = "64286104261",
                CleRIB        = "20",
                LibelleCompte = "Bost CASDEN"
            };
            comptes.Add(compte);
            comptes.Save(Properties.Settings.Default.BanqueAppData);

            comptes = new Comptes();
            comptes.Load(Properties.Settings.Default.BanqueAppData);
            Console.WriteLine($"{comptes.Count} comptes sont présents dans la collection");

            foreach (Compte item in comptes)
            {
                Console.WriteLine(item.ToString());
            }
        }
        public async Task <ActionResult> LinkLoginCallback()
        {
            var user = await GetCurrentUserAsync();

            if (user == null)
            {
                currentUser             = _dbContext.Users.Where(c => c.Id == HttpContext.User.GetUserId()).FirstOrDefault();
                ViewBag.Compte          = currentUser.CompteUnite;
                compte                  = _dbContext.Comptes.Where(c => c.Id == "1").FirstOrDefault();
                ViewBag.ComptePrincipal = compte.SoldeUnite;
                return(View("Error"));
            }
            var info = await _signInManager.GetExternalLoginInfoAsync(User.GetUserId());

            if (info == null)
            {
                return(RedirectToAction(nameof(ManageLogins), new { Message = ManageMessageId.Error }));
            }
            var result = await _userManager.AddLoginAsync(user, info);

            var message = result.Succeeded ? ManageMessageId.AddLoginSuccess : ManageMessageId.Error;

            return(RedirectToAction(nameof(ManageLogins), new { Message = message }));
        }
Пример #27
0
 public FrmNouveauCompte(Comptes comptes) : this()
 {
     listeComptes = comptes;
 }
Пример #28
0
 private void FrmListeComptes_Load(object sender, EventArgs e)
 {
     comptes = new Comptes();
     comptes.Load(Properties.Settings.Default.BanqueAppData);
     comptesBindingSource.DataSource = comptes;
 }
Пример #29
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);
        }
Пример #30
0
        public JObject SaveIdentiteInformation(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);

                //Identity informations
                if (requ["siren"] != null)
                {
                    devis.Siren = requ["siren"].ToObject <string>();
                }
                if (requ["nomSociete"] != null)
                {
                    devis.NomSociete = requ["nomSociete"].ToObject <string>();
                }
                if (requ["pays"] != null)
                {
                    devis.Pays = requ["pays"].ToObject <string>();
                }
                if (requ["activite"] != null)
                {
                    devis.Activite = requ["activite"].ToObject <string>();
                }
                if (requ["ca"] != null)
                {
                    devis.Ch = requ["ca"].ToObject <int>();
                }
                if (requ["factor"] != null)
                {
                    devis.Factor = requ["factor"].ToObject <string>();
                }
                if (requ["produit"] != null)
                {
                    devis.Produit = requ["produit"].ToObject <string>();
                }

                _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();
                    Comptes    cpt          = _context.CompteContact.Select(t => t.IdCptNavigation).Where(p => p.MainContactId == user.Contact.Id).FirstOrDefault();
                    Console.WriteLine("COMPTE ID ====> " + cpt.Id);

                    //Identity informations
                    if (requ["siren"] != null)
                    {
                        devis.Siren = requ["siren"].ToObject <string>();
                    }
                    if (requ["nomSociete"] != null)
                    {
                        devis.NomSociete = requ["nomSociete"].ToObject <string>();
                    }
                    if (requ["pays"] != null)
                    {
                        devis.Pays = requ["pays"].ToObject <string>();
                    }
                    if (requ["activite"] != null)
                    {
                        devis.Activite = requ["activite"].ToObject <string>();
                    }
                    if (requ["ca"] != null)
                    {
                        devis.Ch = requ["ca"].ToObject <int>();
                    }
                    if (requ["factor"] != null)
                    {
                        devis.Factor = requ["factor"].ToObject <string>();
                    }
                    if (requ["produit"] != null)
                    {
                        devis.Produit = requ["produit"].ToObject <string>();
                    }

                    devis.IdCpt = cpt.Id;

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