Beispiel #1
0
        // [ValidateAntiForgeryToken]

        public ActionResult Create(Membre_group membre_group)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string currentUser = User.Identity.GetUserId();
                    if (db.Utilisateur.FirstOrDefault(p => p.UserId == currentUser) != null)
                    {
                        int IdeUser = db.Utilisateur.FirstOrDefault(p => p.UserId == currentUser).ID;
                        if (db.Groupe_thematiqe.FirstOrDefault(p => p.CreatedById == IdeUser) != null)
                        {
                            int currentGroupe = db.Groupe_thematiqe.FirstOrDefault(p => p.CreatedById == IdeUser).ID;
                            if (db.Utilisateur.FirstOrDefault(p => p.ID == membre_group.MembreId) != null)
                            {
                                int IdChildren = db.Utilisateur.FirstOrDefault(p => p.ID == membre_group.MembreId).ID;
                                membre_group.MembreId = IdChildren;
                                membre_group.GroupId  = currentGroupe;

                                db.Membre_group.Add(membre_group);
                                db.SaveChanges();
                                return(RedirectToAction("Consulte", "Groupe", new { id = currentGroupe }));
                            }
                        }
                    }
                }
                catch (Exception) { }
            }


            //ViewBag.GroupId = new SelectList(db.Groupe_thematiqe, "ID", "Nom_groupe", membre_group.GroupId);
            //ViewBag.MembreId = new SelectList(db.Utilisateur, "ID", "UserId", membre_group.MembreId);
            return(View(membre_group));
        }
Beispiel #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            Membre_group membre_group = db.Membre_group.Find(id);

            db.Membre_group.Remove(membre_group);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult add(Membre_group membre_group)
        {
            var membreexi = db.Membre_group.FirstOrDefault(m => m.MembreId == membre_group.MembreId);


            db.Membre_group.Add(membre_group);
            db.SaveChanges();


            return(RedirectToAction("Consulte", "Groupe", new { id = membre_group.GroupId }));
        }
Beispiel #4
0
        public ActionResult Create(Groupe_thematiqe groupe_thematiqe)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var      currentId = User.Identity.GetUserId();
                    var      x         = db.Utilisateur.FirstOrDefault(p => p.UserId == currentId);
                    DateTime aDate     = DateTime.Now;
                    if (groupe_thematiqe.Nom_groupe.Length <= 350)
                    {
                        var grpModel = new Groupe_thematiqe()
                        {
                            CreatedById    = x.ID,
                            Date_createion = aDate,
                            Nom_groupe     = groupe_thematiqe.Nom_groupe,
                            Statut         = false
                        };
                        db.Groupe_thematiqe.Add(grpModel);
                        db.SaveChanges();
                        Membre_group membre_Group = new Membre_group()
                        {
                            GroupId  = grpModel.ID,
                            MembreId = grpModel.CreatedById
                        };
                        db.Membre_group.Add(membre_Group);
                        db.SaveChanges();
                    }
                    else
                    {
                        TempData["Message"] = "limite de caractère est 255 character";
                        return(View(groupe_thematiqe));
                    }
                }
                catch (DbEntityValidationException DbExc)
                {
                    string error = "";
                    foreach (var er in DbExc.EntityValidationErrors)
                    {
                        foreach (var ve in er.ValidationErrors)
                        {
                            error += " - " + ve.ErrorMessage;
                        }
                    }
                    TempData["Message"] = error;
                    return(View(groupe_thematiqe));
                }

                return(RedirectToAction("Index"));
            }

            return(View(groupe_thematiqe));
        }
 public ActionResult Edit([Bind(Include = "Id,GroupId,MembreId")] Membre_group membre_group)
 {
     if (ModelState.IsValid)
     {
         db.Entry(membre_group).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.GroupId  = new SelectList(db.Groupe_thematiqe, "ID", "Nom_groupe", membre_group.GroupId);
     ViewBag.MembreId = new SelectList(db.Utilisateur, "ID", "UserId", membre_group.MembreId);
     return(View(membre_group));
 }
Beispiel #6
0
        // GET: MembreGroup/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Membre_group membre_group = db.Membre_group.Find(id);

            if (membre_group == null)
            {
                return(HttpNotFound());
            }
            return(View(membre_group));
        }
Beispiel #7
0
        // GET: MembreGroup/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Membre_group membre_group = db.Membre_group.Find(id);

            if (membre_group == null)
            {
                return(HttpNotFound());
            }
            ViewBag.GroupId  = new SelectList(db.Groupe_thematiqe, "ID", "Nom_groupe", membre_group.GroupId);
            ViewBag.MembreId = new SelectList(db.Utilisateur, "ID", "UserId", membre_group.MembreId);
            return(View(membre_group));
        }
Beispiel #8
0
        public async Task <ActionResult> CreateActivite(EventsModel eventsModel, int?id, int?idgroupe, bool GAC)
        {
            Activites activites = new Activites();

            activites.Nom_activ       = eventsModel.Title;
            activites.Objectif_activ  = eventsModel.Description;
            activites.Type_ActiviteID = eventsModel.Type_ActiviteID;
            activites.Emplacement     = eventsModel.Location;
            activites.AgendaID        = eventsModel.AgendaId;
            activites.DateStart       = eventsModel.DateStart;
            activites.DateEnd         = eventsModel.DateEnd;
            activites.statu           = false;
            db.Activites.Add(activites);
            try
            {
                await db.SaveChangesAsync();
            }catch (DbEntityValidationException DbExc)
            {
                string error = "";
                foreach (var er in DbExc.EntityValidationErrors)
                {
                    foreach (var ve in er.ValidationErrors)
                    {
                        error += " - " + ve.ErrorMessage;
                    }
                }
                TempData["Message"] = error;
            }

            IList <EventAttendee> AttList = new List <EventAttendee>();

            var          MemL         = db.Membre_group.Where(mg => mg.GroupId == idgroupe);
            Membre_group membre_Group = new Membre_group();

            foreach (var item in MemL)
            {
                EventAttendee eventAttendee = new EventAttendee();
                eventAttendee.Email = item.Utilisateur.Email;
                AttList.Add(eventAttendee);
                //new EventAttendee() { Email = item.Utilisateur.Email };
            }
            ///// Email Send //////////////////////////////
            GetMailData();
            EMail   mail        = new EMail();
            dynamic MailMessage = new MailMessage();

            MailMessage.From = new MailAddress(FromAddress);
            foreach (var item in MemL)
            {
                MailMessage.To.Add(item.Utilisateur.Email);
            }
            MailMessage.Subject    = "Espace MEFRA Notification";
            MailMessage.IsBodyHtml = true;
            MailMessage.Body       = "Nouveau Activité";


            SmtpClient SmtpClient = new SmtpClient();

            SmtpClient.Host        = strSmtpClient;
            SmtpClient.EnableSsl   = bEnableSSL;
            SmtpClient.Port        = Int32.Parse(SMTPPort);
            SmtpClient.Credentials = new System.Net.NetworkCredential(UserID, Password);

            try
            {
                try
                {
                    SmtpClient.Send(MailMessage);
                }
                catch (Exception ex)
                {
                }
            }
            catch (SmtpFailedRecipientsException ex)
            {
                for (int i = 0; i <= ex.InnerExceptions.Length; i++)
                {
                    SmtpStatusCode status = ex.StatusCode;
                    if ((status == SmtpStatusCode.MailboxBusy) | (status == SmtpStatusCode.MailboxUnavailable))
                    {
                        System.Threading.Thread.Sleep(5000);
                        SmtpClient.Send(MailMessage);
                    }
                }
            }


            if (GAC)
            {
                UserCredential credential;
                using (var stream =
                           new FileStream(Path.Combine(Server.MapPath("~/Credentials"), "credentials-MinFin.json"), FileMode.Open, FileAccess.Read))
                {
                    // The file token.json stores the user's access and refresh tokens, and is created
                    // automatically when the authorization flow completes for the first time.
                    string credPath = Path.Combine(Server.MapPath("~/Credentials"), "token" + id + ".json");
                    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.Load(stream).Secrets,
                        Scopes,
                        "user",
                        CancellationToken.None,
                        new FileDataStore(credPath, true)).Result;
                }

                // Create Google Calendar API service.
                var service = new CalendarService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = ApplicationName,
                });
                // Define parameters of request.
                EventsResource.ListRequest request = service.Events.List("primary");
                request.TimeMin      = DateTime.Now;
                request.ShowDeleted  = false;
                request.SingleEvents = true;
                request.MaxResults   = 10;
                request.OrderBy      = EventsResource.ListRequest.OrderByEnum.StartTime;



                Event newEvent = new Event()
                {
                    Summary     = eventsModel.Title,
                    Location    = eventsModel.Location,
                    Description = eventsModel.Description,
                    Start       = new EventDateTime()
                    {
                        DateTime = DateTime.Parse(string.Format("{0:s}", eventsModel.DateStart)),
                        TimeZone = "Africa/Casablanca",
                    },
                    End = new EventDateTime()
                    {
                        DateTime = DateTime.Parse(string.Format("{0:s}", eventsModel.DateEnd)),
                        TimeZone = "Africa/Casablanca",
                    },
                    Recurrence = new String[] { "RRULE:FREQ=DAILY;COUNT=2" },
                    Attendees  = AttList,
                    Reminders  = new Event.RemindersData()
                    {
                        UseDefault = false,
                        Overrides  = new EventReminder[] {
                            new EventReminder()
                            {
                                Method = "email", Minutes = 24 * 60
                            },
                            new EventReminder()
                            {
                                Method = "sms", Minutes = 10
                            },
                        }
                    }
                };

                EventsResource.InsertRequest request2 = service.Events.Insert(newEvent, eventsModel.GoogleCalendarID);

                request2.Execute();
            }

            ViewBag.Type_ActiviteID = new SelectList(db.Type_Activite, "ID", "Nom_type");
            ViewData["idagenda"]    = id;
            ViewData["idgroupe"]    = idgroupe;
            ViewData["GAC"]         = GAC;
            return(RedirectToAction("TestApi", "Agenda", new { id }));
        }