Example #1
0
        public async Task <ActionResult> Submit(int?id, string lbl)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Notification n = await db.Notifications.FindAsync(id);

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

            n.Achat.State     = StateDemande.DemandeAConfirmerFournisseur;
            db.Entry(n).State = EntityState.Modified;
            await db.SaveChangesAsync();

            Notification notif = new Notification {
                AchatID = n.AchatID, Role = SecurityRole.Demandeur, Lbl = "Choisir Fournisseur Pour Demande : " + n.Achat.Des
            };

            db.Notifications.Add(notif);
            ApplicationUser current = db.Users.Where(u => u.UserName == User.Identity.Name).First();
            var             A       = new Models.Avis {
                AchatID = n.AchatID, Accept = true, Lbl = lbl, User = current, Code = AvisCode.init
            };

            db.Avis.Add(A);

            await db.SaveChangesAsync();


            return(RedirectToAction("Index"));
        }
Example #2
0
        public async Task <ActionResult> Submit(int?id, string lbl)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Achat achat = await db.Achats.FindAsync(id);

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

            achat.State           = StateDemande.DemandeAConfirmerFournisseur;
            db.Entry(achat).State = EntityState.Modified;
            await db.SaveChangesAsync();

            Notification notif = new Notification {
                AchatID = achat.ID, Role = SecurityRole.Demandeur, Lbl = "vous devez saisir votre avis technique et choisir un fournisseur Pour la Demande : " + achat.Des
            };

            db.Notifications.Add(notif);
            ApplicationUser current = db.Users.Where(u => u.UserName == User.Identity.Name).First();
            var             A       = new Models.Avis {
                AchatID = achat.ID, Accept = true, Lbl = lbl, User = current, Code = AvisCode.init
            };

            db.Avis.Add(A);

            await db.SaveChangesAsync();


            return(RedirectToAction("Detail", new { id = achat.ID }));
        }
        public bool ApiDeny(int id, string lbl)
        {
            Achat a = db.Achats.Find(id);

            if (a == null)
            {
                return(false);
            }

            ApplicationUser current = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            if (User.IsInRole(SecurityRole.DAF))
            {
                Models.Avis avis = new Models.Avis {
                    AchatID = id, Accept = false, Lbl = lbl, Code = AvisCode.daf, User = current
                };
                a.State           = StateDemande.DemandeRefuser;
                db.Entry(a).State = System.Data.Entity.EntityState.Modified;

                db.Avis.Add(avis);

                db.SaveChanges();
                return(true);
            }
            else if (User.IsInRole(SecurityRole.AUDIT))
            {
                Models.Avis avis = new Models.Avis {
                    AchatID = id, Accept = false, Lbl = lbl, Code = AvisCode.audit, User = current
                };
                a.State           = StateDemande.DemandeRefuser;
                db.Entry(a).State = System.Data.Entity.EntityState.Modified;

                db.Avis.Add(avis);

                db.SaveChanges();
                return(true);
            }
            else if (User.IsInRole(SecurityRole.DG))
            {
                Models.Avis avis = new Models.Avis {
                    AchatID = id, Accept = false, Lbl = lbl, Code = AvisCode.dg, User = current
                };
                a.State           = StateDemande.DemandeRefuser;
                db.Entry(a).State = System.Data.Entity.EntityState.Modified;

                db.Avis.Add(avis);

                db.SaveChanges();
                return(true);
            }

            return(false);
        }
Example #4
0
        public async Task <ActionResult> Fournisseur(int?id, int?fid, string lbl)
        {
            AchaFournisseur af = await db.AchaFournisseurs.FindAsync(fid);

            Achat a = await db.Achats.FindAsync(id);

            ApplicationUser current = db.Users.Where(u => u.UserName == User.Identity.Name).First();

            if (a == null || af == null)
            {
                return(HttpNotFound());
            }


            af.State = StateFournisseur.Chose;

            a.State = StateDemande.DemandeConfirmerFournisseur;

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

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


            var A = new Models.Avis {
                AchatID = a.ID, Accept = true, Lbl = lbl, User = current, Code = AvisCode.demandeur
            };

            Notification notif = new Notification {
                AchatID = af.AchatID, Role = SecurityRole.DAF, Lbl = "Demande choisir Fournisseur"
            };

            db.Notifications.Add(notif);

            db.Avis.Add(A);

            await db.SaveChangesAsync();

            return(RedirectToAction("Detail", new { id = a.ID }));
        }
Example #5
0
        public async Task <ActionResult> Fournisseur(int?id, int?fid, string lbl)
        {
            Notification notification = await db.Notifications.FindAsync(id);

            AchaFournisseur af = await db.AchaFournisseurs.FindAsync(fid);

            Achat a = await db.Achats.FindAsync(notification.AchatID);

            ApplicationUser current = db.Users.Where(u => u.UserName == User.Identity.Name).First();

            if (notification == null || af == null)
            {
                return(HttpNotFound());
            }

            notification.Etat = true;

            af.State = StateFournisseur.Chose;

            a.State = StateDemande.DemandeConfirmerFournisseur;

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

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

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


            var A = new Models.Avis {
                AchatID = notification.AchatID, Accept = true, Lbl = lbl, User = current, Code = AvisCode.demandeur
            };

            db.Avis.Add(A);

            await db.SaveChangesAsync();

            return(RedirectToAction("Fournisseur"));
        }
        public bool Refuser(RestAvis model)
        {
            ApplicationUser current = db.Users.Where(u => u.UserName == model.Email).FirstOrDefault();
            Achat           a       = db.Achats.Find(model.ID);

            if (a == null)
            {
                return(false);
            }

            if (IsInRole(model.Email, SecurityRole.DAF))
            {
                Models.Avis avis = new Models.Avis {
                    AchatID = model.ID, Accept = false, Lbl = model.Lbl, Code = AvisCode.daf, User = current
                };
                a.State           = StateDemande.DemandeRefuser;
                db.Entry(a).State = System.Data.Entity.EntityState.Modified;

                db.Avis.Add(avis);
                Notification notif = new Notification {
                    AchatID = avis.AchatID, Role = SecurityRole.RespAcha, Lbl = "Demande Refuser par : " + current.UserName
                };
                Notification notif1 = new Notification {
                    AchatID = avis.AchatID, Role = SecurityRole.Demandeur, Lbl = "Demande Refuser par : " + current.UserName
                };

                db.Notifications.Add(notif);
                db.Notifications.Add(notif1);
                db.SaveChanges();

                return(true);
            }

            if (IsInRole(model.Email, SecurityRole.AUDIT))
            {
                Models.Avis avis = new Models.Avis {
                    AchatID = model.ID, Accept = false, Lbl = model.Lbl, Code = AvisCode.audit, User = current
                };
                a.State           = StateDemande.DemandeRefuser;
                db.Entry(a).State = System.Data.Entity.EntityState.Modified;

                db.Avis.Add(avis);
                Notification notif = new Notification {
                    AchatID = avis.AchatID, Role = SecurityRole.RespAcha, Lbl = "Demande Refuser par : " + current.UserName
                };
                Notification notif1 = new Notification {
                    AchatID = avis.AchatID, Role = SecurityRole.Demandeur, Lbl = "Demande Refuser par : " + current.UserName
                };

                db.Notifications.Add(notif);
                db.Notifications.Add(notif1);
                db.SaveChanges();

                return(true);
            }

            if (IsInRole(model.Email, SecurityRole.DG))
            {
                Models.Avis avis = new Models.Avis {
                    AchatID = model.ID, Accept = false, Lbl = model.Lbl, Code = AvisCode.dg, User = current
                };
                a.State           = StateDemande.DemandeRefuser;
                db.Entry(a).State = System.Data.Entity.EntityState.Modified;

                db.Avis.Add(avis);
                Notification notif = new Notification {
                    AchatID = avis.AchatID, Role = SecurityRole.RespAcha, Lbl = "Demande Refuser par : " + current.UserName
                };
                Notification notif1 = new Notification {
                    AchatID = avis.AchatID, Role = SecurityRole.Demandeur, Lbl = "Demande Refuser par : " + current.UserName
                };

                db.Notifications.Add(notif);
                db.Notifications.Add(notif1);
                db.SaveChanges();
                return(true);
            }
            return(false);
        }
        public ActionResult Deny(int?id, string lbl)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Achat a = db.Achats.Find(id);

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

            ApplicationUser current = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            if (User.IsInRole(SecurityRole.DAF))
            {
                Models.Avis avis = new Models.Avis {
                    AchatID = id.GetValueOrDefault(), Accept = false, Lbl = lbl, Code = AvisCode.daf, User = current
                };
                a.State           = StateDemande.DemandeRefuser;
                db.Entry(a).State = System.Data.Entity.EntityState.Modified;

                db.Avis.Add(avis);
                Notification notif = new Notification {
                    AchatID = avis.AchatID, Role = SecurityRole.RespAcha, Lbl = "Demande Refuser par : " + current.UserName
                };
                Notification notif1 = new Notification {
                    AchatID = avis.AchatID, Role = SecurityRole.Demandeur, Lbl = "Demande Refuser par : " + current.UserName
                };

                db.Notifications.Add(notif);
                db.Notifications.Add(notif1);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else if (User.IsInRole(SecurityRole.AUDIT))
            {
                Models.Avis avis = new Models.Avis {
                    AchatID = id.GetValueOrDefault(), Accept = false, Lbl = lbl, Code = AvisCode.audit, User = current
                };
                a.State           = StateDemande.DemandeRefuser;
                db.Entry(a).State = System.Data.Entity.EntityState.Modified;

                db.Avis.Add(avis);
                Notification notif = new Notification {
                    AchatID = avis.AchatID, Role = SecurityRole.RespAcha, Lbl = "Demande Refuser par : " + current.UserName
                };
                Notification notif1 = new Notification {
                    AchatID = avis.AchatID, Role = SecurityRole.Demandeur, Lbl = "Demande Refuser par : " + current.UserName
                };

                db.Notifications.Add(notif);
                db.Notifications.Add(notif1);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else if (User.IsInRole(SecurityRole.DG))
            {
                Models.Avis avis = new Models.Avis {
                    AchatID = id.GetValueOrDefault(), Accept = false, Lbl = lbl, Code = AvisCode.dg, User = current
                };
                a.State           = StateDemande.DemandeRefuser;
                db.Entry(a).State = System.Data.Entity.EntityState.Modified;

                db.Avis.Add(avis);
                Notification notif = new Notification {
                    AchatID = avis.AchatID, Role = SecurityRole.RespAcha, Lbl = "Demande Refuser par : " + current.UserName
                };
                Notification notif1 = new Notification {
                    AchatID = avis.AchatID, Role = SecurityRole.Demandeur, Lbl = "Demande Refuser par : " + current.UserName
                };

                db.Notifications.Add(notif);
                db.Notifications.Add(notif1);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(RedirectToAction("Index"));
        }