public string[] GetCommunityCoInfo(long userId)
        {
            string[] list           = new string[2];
            string   communityName  = "No community";
            string   communityApart = "No apartment";
            user     selfUser       = entities.users.Find(userId);

            if (selfUser.create_userid != null)
            {
                long       coadminUserId    = (long)selfUser.create_userid;
                communuser communuserResult = entities.communusers.Where(m => m.user_id == coadminUserId).FirstOrDefault();
                if (communuserResult != null)
                {
                    long      communityID = communuserResult.commun_id;
                    community community   = entities.communities.Find(communityID);
                    communityName  = community.first_name;
                    communityApart = community.apart;
                }
                list[0] = communityName;
                list[1] = communityApart;
                return(list);
            }
            else
            {
                return(list);
            }
        }
        private object getCommunityTwitterFromDB(community res)
        {
            var r = res.CommunitySocialNetwork.FirstOrDefault(item => item.provider == "Twitter");

            if (r != null)
            {
                return(new Twitter()
                {
                    HasToken = true, Token = r.Acess_Token, NotInDB = false
                });
            }
            if (Session["AccessTokenTwitterSecret"] != null && Session["AccessTokenTwitterValue"] != null)
            {
                return new Twitter()
                       {
                           HasToken = true, Token = Session["AccessTokenTwitterSecret"].ToString() + ":" + Session["AccessTokenTwitterValue"].ToString(), NotInDB = true
                       }
            }
            ;

            return(new Twitter()
            {
                HasToken = false, NotInDB = true
            });
        }
        public ActionResult newcommunity(string first_name,
                                         string description, long packageId, string apartment)
        {
            try
            {
                community newCommunity = new community();
                newCommunity.first_name = first_name;
                //  newCommunity.admin_email = admin_email;
                newCommunity.package_id  = packageId;
                newCommunity.description = description;
                newCommunity.created_at  = DateTime.Now;
                newCommunity.apart       = apartment;
                newCommunity.is_active   = false;

                entities.communities.Add(newCommunity);
                entities.SaveChanges();



                return(Redirect(Url.Action("listado", "comunidades", new { area = "webmaster" })));
            }
            catch (Exception ex)
            {
                return(Redirect(Url.Action("agregar", "comunidades", new { area = "webmaster", Error = "Error al agregar " + ex.Message })));
            }
        }
Example #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            community community = db.communities.Find(id);

            community.isDeleted = 1;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #5
0
 public ActionResult Create([Bind(Include = "communitiesId,sectionId,name,description,isDeleted")] community community)
 {
     if (ModelState.IsValid)
     {
         community.isDeleted = 0;
         db.communities.Add(community);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(RedirectToAction("Index"));
 }
Example #6
0
        // GET: webmaster/administradores
        public ActionResult listado(string searchStr = "")
        {
            if (Session["USER_ID"] != null)
            {
                long userId  = (long)Session["USER_ID"];
                user curUser = entities.users.Find(userId);
                List <ShowMessage>        pubMessageList = ep.GetChatMessages(userId);
                List <user>               coadminList    = new List <user>();
                Dictionary <long, string> communityDict  = new Dictionary <long, string>();
                if (searchStr == "")
                {
                    var query = (from r in entities.users where r.role == 3 select r);
                    coadminList = query.ToList();
                }
                else
                {
                    var query = (from r in entities.users
                                 where r.role == 3 &&
                                 (r.first_name1.Contains(searchStr) ||
                                  r.last_name1.Contains(searchStr))
                                 select r);
                    coadminList = query.ToList();
                }

                foreach (var item in coadminList)
                {
                    communuser communuser = entities.communusers.Where(m => m.user_id == item.id).FirstOrDefault();
                    if (communuser != null)
                    {
                        community community = entities.communities.Find(communuser.commun_id);
                        communityDict.Add(item.id, community.first_name);
                    }
                    else
                    {
                        communityDict.Add(item.id, "No community");
                    }
                }
                listadoAdminViewModel viewModel = new listadoAdminViewModel();
                viewModel.side_menu     = "webmaster";
                viewModel.side_sub_menu = "webmaster_listado";

                viewModel.curUser        = curUser;
                viewModel.coadminList    = coadminList;
                viewModel.communityDict  = communityDict;
                viewModel.pubTaskList    = ep.GetNotifiTaskList(userId);
                viewModel.pubMessageList = pubMessageList;
                viewModel.messageCount   = ep.GetUnreadMessageCount(pubMessageList);
                return(View(viewModel));
            }
            else
            {
                return(Redirect(ep.GetLogoutUrl()));
            }
        }
Example #7
0
 public ActionResult Edit([Bind(Include = "communitiesId,sectionId,name,description,isDeleted")] community community)
 {
     if (ModelState.IsValid)
     {
         community.isDeleted       = 0;
         db.Entry(community).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(RedirectToAction("Index"));
 }
Example #8
0
        public static void X()
        {
            string[]  s             = Console.ReadLine().Split(' ');
            int       CountRob      = int.Parse(s[0]);
            int       CountYearLive = int.Parse(s[1]);
            community c             = new community(CountRob);

            for (int i = 0; i < CountYearLive - 1; i++)
            {
                c.LiveIsYear();
            }
            Console.WriteLine(c.Totalrobots());
        }
 public JsonResult DeactiveCom(long id)
 {
     try
     {
         community user = entities.communities.Find(id);
         user.is_active = false;
         entities.SaveChanges();
         return(Json(new { result = "success" }));
     }
     catch (Exception ex)
     {
         return(Json(new { result = "error", exception = ex.Message }));
     }
 }
Example #10
0
        public List <community> GetCommunityList(long userId)
        {
            List <communuser> comxUser = entities.communusers.Where(x => x.user_id == userId).ToList();
            List <community>  commList = new List <community>();

            if (comxUser != null)
            {
                foreach (communuser item in comxUser)
                {
                    community comSearch = entities.communities.Where(x => x.id == item.commun_id).FirstOrDefault();
                    commList.Add(comSearch);
                }
            }
            return(commList);
        }
Example #11
0
        public async Task <OperationResult <community> > GetByIdAsync(int id)
        {
            community community = await communityRepo.GetByIdAsync(id);

            if (community != null)
            {
                return(new OperationResult <community>()
                {
                    Success = true, Message = Messages.COMMUNITY_SUCCESS, Result = community
                });
            }
            return(new OperationResult <community>()
            {
                Success = false, Message = Messages.COMMUNITY_NOT_EXIST
            });
        }
        // GET: webmaster/administradores
        public ActionResult listado(string Error)
        {
            if (Session["USER_ID"] != null)
            {
                long userId       = (long)Session["USER_ID"];
                long communityAct = Convert.ToInt64(Session["CURRENT_COMU"]);
                user curUser      = entities.users.Find(userId);
                List <ShowMessage>        pubMessageList = ep.GetChatMessages(userId);
                List <user>               coadminList    = new List <user>();
                Dictionary <long, string> communityDict  = new Dictionary <long, string>();
                var query = (from r in entities.users
                             where (r.role == 2 || r.role == 4) && r.is_del != true
                             select r);
                coadminList = query.ToList();

                foreach (var item in coadminList)
                {
                    communuser communuser = entities.communusers.Where(m => m.user_id == item.id).FirstOrDefault();
                    if (communuser != null)
                    {
                        community community = entities.communities.Find(communuser.commun_id);
                        communityDict.Add(item.id, community.first_name);
                    }
                    else
                    {
                        communityDict.Add(item.id, "Sin comunidades");
                    }
                }
                listadoAdminViewModel viewModel = new listadoAdminViewModel();
                viewModel.side_menu     = "administradores";
                viewModel.side_sub_menu = "administradores_listado";

                viewModel.curUser        = curUser;
                viewModel.coadminList    = coadminList;
                viewModel.communityDict  = communityDict;
                viewModel.pubTaskList    = ep.GetNotifiTaskList(userId);
                viewModel.pubMessageList = pubMessageList;
                viewModel.messageCount   = ep.GetUnreadMessageCount(pubMessageList);
                ViewBag.msgError         = Error;
                return(View(viewModel));
            }
            else
            {
                return(Redirect(ep.GetLogoutUrl()));
            }
        }
 public ActionResult editar(string Error, long?id)
 {
     if (Session["USER_ID"] != null)
     {
         if (id != null)
         {
             community editCommunity = entities.communities.Find(id);
             if (editCommunity != null)
             {
                 try
                 {
                     long userId  = (long)Session["USER_ID"];
                     user curUser = entities.users.Find(userId);
                     List <ShowMessage>    pubMessageList = ep.GetChatMessages(userId);
                     editarCommunViewModel viewModel      = new editarCommunViewModel();
                     viewModel.curUser        = curUser;
                     viewModel.side_menu      = "comunidades";
                     viewModel.side_sub_menu  = "comunidades_editar";
                     viewModel.packageList    = entities.packages.ToList();
                     viewModel.editCommunity  = editCommunity;
                     viewModel.pubTaskList    = ep.GetNotifiTaskList(userId);
                     viewModel.pubMessageList = pubMessageList;
                     viewModel.messageCount   = ep.GetUnreadMessageCount(pubMessageList);
                     ViewBag.msgError         = Error;
                     return(View(viewModel));
                 }
                 catch (Exception ex)
                 {
                     return(Redirect(Url.Action("listado", "comunidades", new { area = "webmaster", Error = "Editar comunidad: " + ex.Message })));
                 }
             }
             else
             {
                 return(Redirect(Url.Action("listado", "comunidades", new { area = "webmaster", Error = "No existe ese elemento" })));
             }
         }
         else
         {
             return(Redirect(Url.Action("listado", "comunidades", new { area = "webmaster" })));
         }
     }
     else
     {
         return(Redirect(ep.GetLogoutUrl()));
     }
 }
Example #14
0
        public async Task <OperationResult <community> > GetByNameAsync(string name)
        {
            community community = await communityRepo.GetByNameAsync(name);

            if (community != null)
            {
                community.comment = community.comment.OrderByDescending(item => item.initialDate).ToList();
                return(new OperationResult <community>()
                {
                    Success = true, Message = Messages.COMMUNITY_SUCCESS, Result = community
                });
            }
            return(new OperationResult <community>()
            {
                Success = false, Message = Messages.COMMUNITY_NOT_EXIST_NAME
            });
        }
Example #15
0
        public string[] GetCommunityInfo(long userId)
        {
            string[]   list             = new string[3];
            string     communityName    = "No community";
            string     communityApart   = "No apartment";
            string     cID              = "No ID";
            communuser communuserResult = entities.communusers.Where(m => m.user_id == userId).FirstOrDefault();

            if (communuserResult != null)
            {
                long      communityID = communuserResult.commun_id;
                community community   = entities.communities.Find(communityID);
                communityName  = community.first_name;
                communityApart = community.apart;
                cID            = Convert.ToString(communityID);
            }
            list[0] = communityName;
            list[1] = communityApart;
            list[2] = cID;
            return(list);
        }
        public ActionResult editcommunity(long communityID, string first_name,
                                          string description, long packageId, string apartment)
        {
            try
            {
                community editCommunity = entities.communities.Find(communityID);

                editCommunity.updated_at  = DateTime.Now;
                editCommunity.description = description;
                editCommunity.first_name  = first_name;
                editCommunity.package_id  = packageId;
                editCommunity.apart       = apartment;
                entities.SaveChanges();
                entities.communusers.RemoveRange(editCommunity.communusers);

                return(Redirect(Url.Action("listado", "comunidades", new { area = "webmaster" })));
            }
            catch (Exception ex)
            {
                return(Redirect(Url.Action("editar", "comunidades", new { area = "webmaster", id = communityID, Error = "Error al agregar " + ex.Message })));
            }
        }
        public JsonResult ArmarBlogs(long ID)
        {
            long      userId   = (long)Session["USER_ID"];
            int       role     = (int)Session["USER_ROLE"];
            string    content  = "";
            blog      blogs    = entities.blogs.Find(ID);
            community comuBlog = entities.communities.Find(blogs.community_id);

            content += "<div class='Container'><div class='row'><div class='col-sm-12'><div class='single-blog caja'><h2 class='encabezadoBlog'>" + blogs.title + "<span><td>" + Convert.ToDateTime(blogs.blogdate).ToString("dd/MM/yyyy HH:mm") + "</td></span></h2>";
            content += "<p class='autor'><i class='mdi mdi-worker text-primary'></i>" + blogs.author;
            if (blogs.user.role == 3)
            {
                content += "<span><td>Todas las comunidades</td></span></p>";
            }
            else
            {
                if (blogs.community_id != null && comuBlog != null)
                {
                    content += "<span><td>Comunidad: " + comuBlog.first_name + "</td></span></p>";
                }
                else
                {
                    content += "<span><td>No hay comunidad asociada</td></span></p>";
                }
            }
            content += blogs.content.Replace('"', '\'');
            content += "<p class='fecha' style='padding-top:15px!important'>";
            content += "<a href='#' ><a href = '" + Url.Action("editarblog", "comunicaciones", new { area = "webmaster", blogID = blogs.id }).ToString() + "'><button type = 'button' class='btn btn-primary waves-effect waves-light btn-sm mr-1 mb-1'";
            content += "data-toggle='tooltip' data-placement='top' title='Editar'><i class='mdi mdi-lead-pencil'></i></button></a>";
            content += "<a href = '#' class='Eliminar'  data-id='" + blogs.id + "' ><button type = 'button' class='btn btn-danger waves-effect waves-light btn-sm mr-1 mb-1'";
            content += "data-toggle='tooltip' data-placement='top' title='Eliminar'><i class='mdi mdi-close'></i></button></a>";
            content += "<a href='#' class='Like' data-id='" + blogs.id + "' ><span><i class='fa fa-thumbs-o-up'></i> like " + blogs.CantLike + "</span> </a>" +
                       "<a href = '" + Url.Action("agregarcomentario", "comunicaciones", new { area = "webmaster", blogID = blogs.id }).ToString() + "'><span style='padding-right: 18px;'> <i class='fa fa-comment-o'></i> Comentar </span> </a>" +
                       "</p></div></div></div></div>";

            return(Json(content));
        }
Example #18
0
 //public GameObject friendRequestDialog;
 // Use this for initialization
 void Awake()
 {
     instance = this;
 }
        public void GetCommunity()
        {
            community res = com.GetByIdAsync(1).Result;

            Assert.AreEqual("cenas", res.name);
        }
Example #20
0
 public void add(community entity)
 {
     cmn.Insert(entity.Ownerid, entity.Date, entity.Name, entity.Category);
 }
Example #21
0
 public communityDto(community c)
 {
     codeC = c.codeC;
     nameC = c.nameC;
 }
        public JsonResult DeleteCommunity(long id)
        {
            try
            {
                List <communuser> communusers = entities.communusers.Where(m => m.commun_id == id).ToList();
                List <long>       idAdmins    = new List <long>();

                //Desactivando los Coadmins que administran esta comunidad y almacenando Id de los Coadmins
                foreach (var item in communusers)
                {
                    user userE = entities.users.Find(item.user_id);
                    userE.is_active = false;
                    entities.SaveChanges();
                    idAdmins.Add(userE.id);
                }
                entities.communusers.RemoveRange(communusers);

                //Reactivar Coadmin que administran otras comunidades
                foreach (var idItem in idAdmins)
                {
                    List <communuser> comunS = entities.communusers.Where(x => x.user_id == idItem && x.commun_id != id).ToList();
                    if (comunS.Count > 0)
                    {
                        user userE = entities.users.Find(idItem);
                        userE.is_active = true;
                        entities.SaveChanges();
                    }
                }

                List <Titulo> titulosC     = entities.Titulos.Where(m => m.IdCommunity == id).ToList();
                List <long>   idsTitulares = new List <long>();
                //Almacenando Id de los Titulares para eliminar
                foreach (var item2 in titulosC)
                {
                    idsTitulares.Add(item2.IdUser);
                }

                foreach (var item3 in idsTitulares)
                {
                    List <Titulo> tituloDiferente = entities.Titulos.Where(x => x.IdUser == item3 && x.IdCommunity != id).ToList();
                    if (tituloDiferente.Count == 0)
                    {
                        List <chatmessage> chatmessages = entities.chatmessages.Where(m => m.from_user_id == item3 ||
                                                                                      m.to_user_id == item3).ToList();
                        entities.chatmessages.RemoveRange(chatmessages);

                        List <bank> banks = entities.banks.Where(m => m.user_id == item3).ToList();
                        foreach (var itembk in banks)
                        {
                            List <fee> fees = entities.fees.Where(m => m.bank_id == itembk.id).ToList();
                            entities.fees.RemoveRange(fees);
                        }
                        entities.banks.RemoveRange(banks);
                        // Delete CreditCards
                        List <creditcard> creditcards = entities.creditcards.Where(m => m.user_id == item3).ToList();
                        entities.creditcards.RemoveRange(creditcards);
                        List <taskuser> taskusers = entities.taskusers.Where(m => m.user_id == item3).ToList();
                        entities.taskusers.RemoveRange(taskusers);
                        List <uso> usos = entities.usoes.Where(m => m.create_userid == item3).ToList();
                        entities.usoes.RemoveRange(usos);
                        List <emailtheme> emailthemes = entities.emailthemes.Where(m => m.user_id == item3).ToList();
                        entities.emailthemes.RemoveRange(emailthemes);
                        List <payment> payments = entities.payments.Where(m => m.user_id == item3).ToList();
                        entities.payments.RemoveRange(payments);
                        List <onlineuser> onlineusers = entities.onlineusers.Where(m => m.user_id == item3).ToList();
                        entities.onlineusers.RemoveRange(onlineusers);
                        user usuario = entities.users.Find(item3);
                        entities.users.Remove(usuario);
                    }
                }

                // Delete blogs
                List <blog> blogs = entities.blogs.Where(m => m.community_id == id).ToList();
                foreach (var itemb in blogs)
                {
                    List <blogcomment> blogcomments = entities.blogcomments.Where(m => m.blog_id == itemb.id).ToList();
                    entities.blogcomments.RemoveRange(blogcomments);
                }
                entities.blogs.RemoveRange(blogs);

                // Delete cuotas
                List <fee> feeList = entities.fees.Where(m => m.community_id == id).ToList();
                entities.blogs.RemoveRange(blogs);

                // Delete Tareas
                List <task> tareas = entities.tasks.Where(m => m.community_id == id).ToList();
                foreach (var itemTareas in tareas)
                {
                    List <taskcomment> taskcomments = entities.taskcomments.Where(m => m.task_id == itemTareas.id).ToList();
                    entities.taskcomments.RemoveRange(taskcomments);
                }
                entities.tasks.RemoveRange(tareas);

                // Delete Contactos
                List <contactinfo> contactos = entities.contactinfoes.Where(m => m.community_id == id).ToList();
                entities.contactinfoes.RemoveRange(contactos);

                // Delete Facilidades
                List <efac> facilidades = entities.efacs.Where(m => m.community_id == id).ToList();
                foreach (var itemEfac in facilidades)
                {
                    List <book> bookList = entities.books.Where(m => m.id_efac == itemEfac.id).ToList();
                    entities.books.RemoveRange(bookList);
                }
                entities.efacs.RemoveRange(facilidades);

                List <Vehiculo> vehiculos = entities.Vehiculos.Where(x => x.Titulo.IdCommunity == id).ToList();
                entities.Vehiculos.RemoveRange(vehiculos);
                List <Titulo> titulos = entities.Titulos.Where(x => x.IdCommunity == id).ToList();
                entities.Titulos.RemoveRange(titulos);

                List <@event> eventos = entities.events.Where(x => x.community_id == id).ToList();
                entities.Titulos.RemoveRange(titulos);

                List <document> documentos = entities.documents.Where(x => x.community_id == id).ToList();
                entities.documents.RemoveRange(documentos);

                List <document_type> documentos_ti = entities.document_type.Where(x => x.community_id == id).ToList();
                entities.document_type.RemoveRange(documentos_ti);

                community delCommunity = entities.communities.Find(id);
                entities.communities.Remove(delCommunity);
                entities.SaveChanges();
                return(Json(new { result = "success" }));
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    result = "error",
                    exception = ex.Message
                }));
            }
        }
Example #23
0
        // GET: coadmin/control
        public ActionResult panel()
        {
            controlViewModel viewModel = new controlViewModel();

            if (Session["USER_ID"] != null)
            {
                try
                {
                    long userId  = (long)Session["USER_ID"];
                    user curUser = entities.users.Find(userId);
                    List <ShowMessage>   pubMessageList         = ep.GetChatMessages(userId);
                    List <document_type> document_category_list = entities.document_type.ToList();

                    communityList = ep.GetCommunityList(userId);

                    if (communityList.Count == 0)
                    {
                        viewModel.side_menu              = "control_panel";
                        viewModel.side_sub_menu          = "";
                        viewModel.document_category_list = document_category_list;
                        viewModel.curUser        = curUser;
                        viewModel.pubTaskList    = ep.GetNotifiTaskList(userId);
                        viewModel.pubMessageList = pubMessageList;
                        viewModel.messageCount   = ep.GetUnreadMessageCount(pubMessageList);
                        viewModel.isPartial      = false;
                        viewModel.communityList  = communityList;
                        return(View(viewModel));
                    }
                    else
                    {
                        if (Session["CURRENT_COMU"] == null)
                        {
                            community firstCommu    = communityList.FirstOrDefault();
                            long      selectedCommu = firstCommu.id;
                            Session["CURRENT_COMU"] = selectedCommu;
                        }
                        else
                        {
                            long             Id             = Convert.ToInt64(Session["CURRENT_COMU"]);
                            List <community> ordenCommunity = new List <community>();
                            community        selectedCommu  = entities.communities.Find(Id);
                            ordenCommunity.Add(selectedCommu);
                            foreach (community item in communityList)
                            {
                                if (item.id != selectedCommu.id)
                                {
                                    ordenCommunity.Add(item);
                                }
                            }

                            communityList.Clear();

                            foreach (community item2 in ordenCommunity)
                            {
                                communityList.Add(item2);
                            }
                        }
                        viewModel.communityList          = communityList;
                        viewModel.side_menu              = "control_panel";
                        viewModel.side_sub_menu          = "";
                        viewModel.document_category_list = document_category_list;
                        viewModel.curUser        = curUser;
                        viewModel.pubTaskList    = ep.GetNotifiTaskList(userId);
                        viewModel.pubMessageList = pubMessageList;
                        viewModel.messageCount   = ep.GetUnreadMessageCount(pubMessageList);
                        viewModel.isPartial      = false;
                        return(View(viewModel));
                    }
                }
                catch (Exception ex)
                {
                    return(Redirect(Url.Action("Index", "Error")));
                }
            }
            else if (Session["SUS_USER_ID"] != null)
            {
                long userId  = (long)Session["SUS_USER_ID"];
                user curUser = entities.users.Find(userId);
                List <ShowMessage>   pubMessageList         = ep.GetChatMessages(userId);
                List <document_type> document_category_list = entities.document_type.ToList();

                communityList           = ep.GetCommunityList(userId);
                viewModel.communityList = communityList;

                viewModel.side_menu              = "control_panel";
                viewModel.side_sub_menu          = "";
                viewModel.document_category_list = document_category_list;
                viewModel.curUser        = curUser;
                viewModel.pubTaskList    = ep.GetNotifiTaskList(userId);
                viewModel.pubMessageList = pubMessageList;
                viewModel.messageCount   = ep.GetUnreadMessageCount(pubMessageList);
                viewModel.isPartial      = false;
                return(View(viewModel));
            }
            else
            {
                return(Redirect(ep.GetLogoutUrl()));
            }
        }
Example #24
0
        // GET: community
        public ActionResult community()
        {
            if (Session["USER_ID"] != null)
            {
                try
                {
                    long userId       = (long)Session["USER_ID"];
                    long communityAct = Convert.ToInt64(Session["CURRENT_COMU"]);
                    user curUser      = entities.users.Find(userId);
                    List <ShowMessage>        pubMessageList = ep.GetChatMessages(userId);
                    communityControlViewModel viewModel      = new communityControlViewModel();
                    titulosList    = ep.GetTitulosByTitular(userId);
                    listComunities = ep.GetCommunityListByTitular(titulosList);
                    if (listComunities.Count == 0)
                    {
                        viewModel.side_menu              = "control";
                        viewModel.side_sub_menu          = "control";
                        viewModel.document_category_list = entities.document_type.Where(x => x.community_id == communityAct).ToList();
                        viewModel.curUser        = curUser;
                        viewModel.pubTaskList    = ep.GetNotifiTaskList(userId);
                        viewModel.pubMessageList = pubMessageList;
                        viewModel.messageCount   = ep.GetUnreadMessageCount(pubMessageList);
                        viewModel.titulosList    = titulosList;
                        viewModel.communityList  = listComunities;
                        return(View(viewModel));
                    }
                    else
                    {
                        if (Session["CURRENT_COMU"] == null)
                        {
                            long      selectedCommu = 0;
                            community firstCommu    = listComunities.FirstOrDefault();
                            selectedCommu           = firstCommu.id;
                            Session["CURRENT_COMU"] = selectedCommu;
                            viewModel.communityID1  = selectedCommu;
                        }
                        else
                        {
                            long             Id             = Convert.ToInt64(Session["CURRENT_COMU"]);
                            List <community> ordenCommunity = new List <community>();
                            community        selectedCommu  = entities.communities.Find(Id);
                            ordenCommunity.Add(selectedCommu);
                            foreach (community item in listComunities)
                            {
                                if (item.id != selectedCommu.id)
                                {
                                    ordenCommunity.Add(item);
                                }
                            }

                            listComunities.Clear();

                            foreach (community item2 in ordenCommunity)
                            {
                                listComunities.Add(item2);
                            }
                        }
                        viewModel.communityList          = listComunities;
                        viewModel.side_menu              = "control";
                        viewModel.side_sub_menu          = "control";
                        viewModel.document_category_list = entities.document_type.Where(x => x.community_id == communityAct).ToList();
                        viewModel.curUser        = curUser;
                        viewModel.pubTaskList    = ep.GetNotifiTaskList(userId);
                        viewModel.pubMessageList = pubMessageList;
                        viewModel.messageCount   = ep.GetUnreadMessageCount(pubMessageList);
                        viewModel.titulosList    = titulosList;
                        return(View(viewModel));
                    }
                }
                catch (Exception ex)
                {
                    return(Redirect(Url.Action("error", "control", new { Error = "Community: " + ex.Message })));
                }
            }
            else
            {
                return(Redirect(ep.GetLogoutUrl()));
            }
        }
Example #25
0
        public async Task <ActionResult> SubmitRegister(string Name, string LastName, string LastNameMaterno, string CommunityName,
                                                        string Address, string PhoneNumber, string Email, string Password,
                                                        string ConfirmPassword, long PackageId)
        {
            Session["Reg_Name"]            = Name;
            Session["Reg_LastName"]        = LastName;
            Session["Reg_LastNameMaterno"] = LastNameMaterno;
            Session["Reg_CommunityName"]   = CommunityName;
            Session["Reg_Address"]         = Address;
            Session["Reg_PhoneNumber"]     = PhoneNumber;
            Session["Reg_Email"]           = Email;
            Session["Reg_Password"]        = Password;
            Session["Reg_ConfirmPassword"] = ConfirmPassword;

            if (Password != ConfirmPassword)
            {
                Session["Register_Result"] = "Confirm password have to matach with password";
            }
            else
            {
                try
                {
                    suscribe suscribe = entities.suscribes.Where(m => m.email.Equals(Email) &&
                                                                 m.package_id == PackageId).FirstOrDefault();
                    if (suscribe != null)
                    {
                        Session["Register_Result"] = "User already exist for same email";
                    }
                    else
                    {
                        // Check PackageId is valid
                        package package = entities.packages.Where(m => m.id == PackageId).FirstOrDefault();

                        if (package != null)
                        {
                            // Insert new suscribe coadmin
                            user user1 = new user();
                            user1.first_name1       = Name;
                            user1.last_name1        = LastName;
                            user1.mother_last_name1 = LastNameMaterno;
                            user1.first_name2       = CommunityName;
                            user1.postal_address    = Address;
                            user1.phone_number1     = PhoneNumber;
                            user1.email             = Email;
                            user1.password          = ep.Encrypt(Password);
                            user1.is_admin          = false;
                            user1.is_logged         = false;
                            user1.is_active         = false;
                            user1.role       = 2;
                            user1.acq_date   = DateTime.Now;
                            user1.package_id = PackageId;
                            user1.is_paid    = false;
                            entities.users.Add(user1);
                            entities.SaveChanges();
                            // create new community for current coadmin
                            community community = new community();
                            community.admin_email = Email;
                            community.package_id  = PackageId;
                            community.description = "";
                            community.first_name  = CommunityName;
                            community.created_at  = DateTime.Now;
                            community.updated_at  = DateTime.Now;
                            community.is_active   = true;
                            community.apart       = "";
                            entities.communities.Add(community);
                            entities.SaveChanges();
                            // Create communuser
                            communuser communuser = new communuser();
                            communuser.commun_id = community.id;
                            communuser.user_id   = user1.id;
                            entities.communusers.Add(communuser);
                            entities.SaveChanges();
                            Session["USER_ID"]         = user1.id;
                            Session["USER_ROLE"]       = 2;
                            Session["Active"]          = false;
                            Session["PACK_ID"]         = PackageId;
                            Session["Register_Result"] = "success";
                            string            patialView = "~/Views/iniciar/emailing.cshtml";
                            emailingViewModel viewModel  = new emailingViewModel();
                            viewModel.firstName = CommunityName;
                            viewModel.lastName  = LastName;
                            viewModel.fromEmail = "*****@*****.**";
                            viewModel.toEmail   = Email;
                            string emailTemplate = ViewRenderer.RenderPartialView(patialView, viewModel);
                            int    a             = await ep.SendAlertEmail("", Email, CommunityName + " " + LastName,
                                                                           "añadir título", "has sido añadido como titular\n password: "******"Register_Result"] = "PackageId is invalid";
                        }
                    }
                }
                catch (Exception ex)
                {
                    Session["Register_Result"] = ex.Message;
                }
            }

            return(Redirect(Url.Action("Register", "suscribe", new { packageId = PackageId })));
        }
        public ActionResult ver(long?id)
        {
            if (Session["USER_ID"] != null)
            {
                if (id != null)
                {
                    community viewCommunity = entities.communities.Find(id);
                    if (viewCommunity != null)
                    {
                        try
                        {
                            long userId  = (long)Session["USER_ID"];
                            user curUser = entities.users.Find(userId);
                            List <ShowMessage> pubMessageList = ep.GetChatMessages(userId);
                            List <communuser>  commonuserList = entities.communusers.Where(m => m.commun_id == id).ToList();
                            List <user>        titularList    = new List <user>();
                            foreach (var item in commonuserList)
                            {
                                user        coadminUser    = entities.users.Find(item.user_id);
                                List <user> subTitularList = entities.users.Where(m => m.create_userid == coadminUser.id).ToList();
                                titularList.AddRange(subTitularList);
                            }
                            List <user> coadminList = new List <user>();
                            var         query       = (from r in entities.users
                                                       where (r.role == 2 || r.role == 4) && r.is_del != true
                                                       select r);
                            coadminList = query.ToList();
                            verCommunViewModel viewModel = new verCommunViewModel();
                            viewModel.curUser       = curUser;
                            viewModel.side_menu     = "comunidades";
                            viewModel.side_sub_menu = "comunidades_ver";

                            viewModel.packageList   = entities.packages.ToList();
                            viewModel.viewCommunity = viewCommunity;
                            package package = entities.packages.Find(viewCommunity.package_id);
                            viewModel.package_name   = package.first_name;
                            viewModel.pubTaskList    = ep.GetNotifiTaskList(userId);
                            viewModel.pubMessageList = pubMessageList;
                            viewModel.messageCount   = ep.GetUnreadMessageCount(pubMessageList);
                            viewModel.titularList    = titularList;
                            viewModel.coadminList    = coadminList;
                            return(View(viewModel));
                        }
                        catch (Exception ex)
                        {
                            return(Redirect(Url.Action("listado", "comunidades", new { area = "webmaster", Error = "Ver comunidad: " + ex.Message })));
                        }
                    }
                    else
                    {
                        return(Redirect(Url.Action("listado", "comunidades", new { area = "webmaster", Error = "No existe ese elemento" })));
                    }
                }
                else
                {
                    return(Redirect(Url.Action("listado", "comunidades", new { area = "webmaster" })));
                }
            }
            else
            {
                return(Redirect(ep.GetLogoutUrl()));
            }
        }