예제 #1
0
        public ActionResult Create(PollFormModel model)
        {
            if (ModelState.IsValid)
            {
                var item = Mapper.Map <PollFormModel, Poll>(model);


                // Object
                if (model.Object_id > 0)
                {
                    item.Object = GetSession.Get <Poll>(model.Object_id);
                }
                else
                {
                    item.Object = null;
                }

                // Anonymous User
                if (model.AnonymousUser_id > 0)
                {
                    item.AnonymousUser = GetSession.Get <Employee>(model.AnonymousUser_id);
                }
                else
                {
                    item.AnonymousUser = null;
                }


                GetSession.Save(item);

                return(RedirectToAction("edit", new { id = item.Id }));
            }

            return(View(model));
        }
        public ActionResult Create(FlashBannerFormModel model, HttpPostedFileBase uploadPicture)
        {
            if (ModelState.IsValid)
            {
                var item = Mapper.Map <FlashBannerFormModel, FlashBanner>(model);

                if (uploadPicture != null && uploadPicture.ContentLength > 0)
                {
                    if (model.TypeId == 1)
                    {
                        item.Banner += "|" + SaveFile(uploadPicture, "flashBanners", item.Banner);
                    }
                    else
                    {
                        item.Banner = SaveFile(uploadPicture, "flashBanners", item.Banner);
                    }
                }

                int maxOrder = GetSession.Query <FlashBanner>()
                               .Max(x => (int?)x.BannerOrder) ?? 0;

                item.BannerOrder = maxOrder + 1;

                GetSession.Save(item);
                return(RedirectToAction("Index"));
            }

            model.InitMembers();

            return(View(model));
        }
예제 #3
0
        public ActionResult UploadPhotos(IList <HttpPostedFileBase> photos)
        {
            var employee = new Employee {
                Id = GetEmployeeId
            };

            foreach (var item in photos)
            {
                if (item != null && item.ContentLength > 0)
                {
                    var picture = Guid.NewGuid() + ".jpg";
                    var image   = new WebImage(item.InputStream);

                    image.Resize(601, 601)
                    .Crop(1, 1)
                    .Save("~/public/UserFiles/employeephotos/big/" + picture, "image/jpeg")
                    .Resize(101, 101)
                    .Crop(1, 1)
                    .Save("~/public/UserFiles/employeephotos/small/" + picture, "image/jpeg");

                    GetSession.Save(new EmployeePhoto
                    {
                        Employee = employee,
                        FileName = picture
                    });
                }
            }
            return(RedirectToAction("Card", new { employee.Id }));
        }
예제 #4
0
        public ActionResult Create(DocFormModel model, HttpPostedFileBase upload_file, FormCollection coll)
        {
            string tt = Request.Form["upload_text"];

            if (upload_file != null)
            {
                var    uploaded_file = Guid.NewGuid();
                var    u_file        = upload_file.InputStream;
                int    index         = upload_file.FileName.IndexOf('.');
                string new_name      = uploaded_file + "." + upload_file.FileName.Substring(index + 1);

                var path = Path.Combine(Server.MapPath("~/Public/userfiles/docs"), new_name);
                upload_file.SaveAs(path);
                model.Url = new_name;
            }
            else
            {
                model.Url = Request.Form["upload_text"];
            }


            var item = Mapper.Map <DocFormModel, Doc>(model);



            if (Request.Form["userSS"] != null)
            {
                item.UsersAllowed = Request.Form["userSS"].ToString();
            }


            if (Request.Form["Units[]"] != null)
            {
                item.Units = Request.Form["Units[]"].ToString();
            }
            if (string.IsNullOrEmpty(Request.Form["Units[]"]))
            {
                item.Units = "0";
            }

            if (coll["isAvailable2All"] == "on")
            {
                item.isAvailable2All = true;
            }
            else
            {
                item.isAvailable2All = false;
            }

            item.NotSubmited = GetSession.QueryOver <Employee>().RowCount().ToString();

            item.Submited = "0";



            GetSession.Save(item);

            return(RedirectToAction("Index"));
        }
예제 #5
0
        public ActionResult Create(JobFormModel model)
        {
            var item = Mapper.Map <JobFormModel, Job>(model);

            GetSession.Save(item);

            return(RedirectToAction("Index"));
        }
예제 #6
0
        public ActionResult Create(CalendarFormModel model)
        {
            var item = Mapper.Map <CalendarFormModel, Calendar>(model);

            GetSession.Save(item);

            return(RedirectToAction("Index"));
        }
예제 #7
0
        public ActionResult Create(StreamLinkFormModel model)
        {
            var item = Mapper.Map <StreamLinkFormModel, StreamLink>(model);

            GetSession.Save(item);

            return(RedirectToAction("Index"));
        }
예제 #8
0
        public ActionResult UpdateTitle(long id, string newTitle)
        {
            ForumItem forumTarget = GetSession.Get <ForumItem>(id);

            forumTarget.Title = newTitle;

            GetSession.Save(forumTarget);
            return(Redirect("/ForumItems/"));
        }
예제 #9
0
        public ActionResult ForumActiveUpdate(long id, bool isActive)
        {
            ForumItem forumTarget = GetSession.Get <ForumItem>(id);

            forumTarget.Active = isActive;

            GetSession.Save(forumTarget);
            return(Redirect("/ForumItems/"));
        }
예제 #10
0
        public ActionResult ForumAllowAllUpdate(long id, bool isAvailableTooAll)
        {
            ForumItem forumTarget = GetSession.Get <ForumItem>(id);

            forumTarget.isAvailableTooAll = isAvailableTooAll;

            GetSession.Save(forumTarget);
            return(Redirect("/ForumItems/"));
        }
예제 #11
0
        public ActionResult Create(WikiFormModel model)
        {
            var item = Mapper.Map <WikiFormModel, Wiki>(model);

            // int maxOrder = GetSession.Query<Wiki>().Where(x => x.Letter == item.Letter).Count();

            // item.Id = maxOrder + 1;
            GetSession.Save(item);

            return(RedirectToAction("Index", new { model.Letter }));
        }
예제 #12
0
        public ActionResult Create(EmployeeFormModel model)
        {
            if (ModelState.IsValid)
            {
                var item = Mapper.Map <EmployeeFormModel, Employee>(model);
                GetSession.Save(item);
                return(RedirectToAction("List"));
            }

            model.InitMembers(GetSession);

            return(View(model));
        }
예제 #13
0
        public ActionResult Create(DepartmentFormModel model)
        {
            if (ModelState.IsValid)
            {
                var item = Mapper.Map <DepartmentFormModel, Department>(model);

                GetSession.Save(item);

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
예제 #14
0
        public JavaScriptResult UpdateAdmin(long forumId, long adminId)
        {
            ForumItem forumTarget = GetSession.Get <ForumItem>(forumId);

            Employee temp = GetSession.Get <Employee>(adminId);

            forumTarget.Admin = temp;

            GetSession.Save(forumTarget);
            string js = @"alert('מנהל פורום עודכן בהצלחה!')";

            return(JavaScript(js));
        }
예제 #15
0
        private void AddCategoryPage(Page page)
        {
            int maxOrder = GetSession.Query <Page>()
                           .Where(x => x.Parent.Id == page.Parent.Id && x.SectionId == page.SectionId)
                           .Max(x => (int?)x.PageOrder) ?? 0;

            page.PageOrder   = maxOrder + 1;
            page.IsInternal  = true;
            page.UpdatedDate = DateTime.Now;

            GetSession.Save(page);

            //return RedirectToAction("Index", new { model.ParentId, model.SectionId });
        }
예제 #16
0
        public ActionResult Create(PollItemFormModel model)
        {
            if (ModelState.IsValid)
            {
                var item = Mapper.Map <PollItemFormModel, PollItem>(model);

                item.Poll = GetSession.Get <Poll>(model.Poll_Id);

                GetSession.Save(item);

                return(Redirect(Url.RouteUrl(new { controller = "Polls", action = "Edit", id = model.Poll_Id }) + "#items"));
                //return RedirectToAction("Edit", "Polls", new { id = model.Poll_Id });
            }
            return(View(model));
        }
예제 #17
0
        public void UpdateJobs()
        {
            var excel = new ExcelQueryFactory();

            string[] ex_names = MvcApplication.Config("excel_name").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            for (int ex_name = 0; ex_name < ex_names.Length; ex_name++)
            {
                excel.FileName = ex_names[ex_name];



                var result_employees = from c
                                       in excel.WorksheetNoHeader(0)
                                       select c;


                List <JobTitle> existing_jobs      = (List <JobTitle>)GetSession.QueryOver <JobTitle>().List();
                List <string>   existing_jobs_list = new List <string>();

                foreach (var job in existing_jobs)
                {
                    if (!existing_jobs_list.Contains(job.Name))
                    {
                        existing_jobs_list.Add(job.Name);
                    }
                }


                foreach (var new_job in result_employees)
                {
                    if (!string.IsNullOrEmpty(new_job[8].ToString().Trim()) && !existing_jobs_list.Contains(new_job[8].ToString().Trim()))
                    {
                        JobTitleFormModel model = new JobTitleFormModel()
                        {
                            Name = new_job[8].ToString().Trim()
                        };

                        var item = Mapper.Map <JobTitleFormModel, JobTitle>(model);
                        GetSession.Save(item);
                        existing_jobs_list.Add(new_job[8].ToString().Trim());
                    }
                }
            }
        }
예제 #18
0
        public ActionResult Create(ForumItemModel model)
        {
            var  results = Request.Form["ForumUsers[]"];
            long adminId;

            if (!string.IsNullOrEmpty(Request.Form["Admin"]))
            {
                adminId = Convert.ToInt64(Request.Form["Admin"]);
            }
            else
            {
                adminId = GetEmployeeId;
            }

            ForumItem newForum = new ForumItem()
            {
                Title      = !string.IsNullOrEmpty(Request.Form["Title"]) ? Request.Form["Title"] : " פורום חדש",
                Active     = (Request.Form["Active"] == "on") ? true : false,
                ForumUsers = Request.Form["ForumUsers[]"],



                Admin = GetSession.Get <Employee>(adminId)
            };

            GetSession.Save(newForum);
            #region ado.net



            //string theTitle = Request.Form["Title"];
            //long theAdmin = Convert.ToInt32(Request.Form["Admin"]);
            //bool theActive = (Request.Form["Active"] == "on") ? true : false;
            //SqlConnection sqlConnection1 = new SqlConnection(cs);
            //SqlCommand cmd = new SqlCommand();
            //Int32 rowsAffected;
            //cmd.CommandText = "INSERT into portal_ForumItem(Title,Active,Admin_id,ForumUsers) values ('" + theTitle + "', '" + theActive + "', " + theAdmin + ", '" + results + "')";
            //cmd.CommandType = CommandType.Text;
            //cmd.Connection = sqlConnection1;
            //sqlConnection1.Open();
            //rowsAffected = cmd.ExecuteNonQuery();
            //sqlConnection1.Close();
            #endregion
            return(Redirect("/ForumItems/"));
        }
예제 #19
0
        public ActionResult AutoCreate()
        {
            int categoryId = 1;


            var cats = GetSession.QueryOver <Forum>()
                       .OrderBy(x => x.CategoryId).Desc().List();

            List <int> categories = new List <int>();

            foreach (Forum forum in cats)
            {
                if (!categories.Contains(forum.CategoryId))
                {
                    categories.Add(forum.CategoryId);
                }
            }
            if (categories.Count() > 0)
            {
                categoryId = categories[0] + 1;
            }


            ForumFormModel model = new ForumFormModel()
            {
                Body          = "פורום חדש",
                CategoryTitle = "פורום חדש",
                Subject       = "פורום חדש",
                CategoryId    = categoryId
            };

            var item = Mapper.Map <ForumFormModel, Forum>(model);

            item.CreatedBy = new Employee
            {
                Id = GetEmployeeId
            };
            ViewData["catId"] = categoryId;
            GetSession.Save(item);

            return(RedirectToAction("List", new { categoryId = categoryId }));
        }
예제 #20
0
        public JavaScriptResult UpdateUsers(ForumItemModel model, string[] users, long id)
        {
            string result = "";

            if (users != null)
            {
                if (users.Length > 0)
                {
                    result = string.Join(",", users);
                    //return Redirect("/ForumItems/");
                }
            }



            ForumItem forumTarget = GetSession.Get <ForumItem>(id);

            forumTarget.ForumUsers = result;

            GetSession.Save(forumTarget);

            #region ado.net
            //string theTitle = Request.Form["Title"];
            //long theAdmin = Convert.ToInt32(Request.Form["Admin"]);
            //long theId = Convert.ToInt32(Request.Form["Id"]);
            //bool theActive = (Request.Form["Active"] == "on") ? true : false;
            //SqlConnection sqlConnection1 = new SqlConnection(cs);
            //SqlCommand cmd = new SqlCommand();
            //Int32 rowsAffected;
            //cmd.CommandText = "UPDATE portal_ForumItem SET Title = '" + theTitle + "', Admin_id = " + theAdmin + ", Active = '" + theActive + "', ForumUsers = '" + result + "' WHERE Id = " + theId + "";
            ////cmd.CommandText = "UPDATE portal_ForumItem SET Title = '" + theTitle + "', Admin_id = " + theAdmin + ", Active = '" + theActive + "' WHERE Id = "+theId+"";
            //cmd.CommandType = CommandType.Text;
            //cmd.Connection = sqlConnection1;
            //sqlConnection1.Open();
            //rowsAffected = cmd.ExecuteNonQuery();
            //sqlConnection1.Close();
            #endregion
            //return RedirectToAction("index");
            string js = @"alert('עודכן בהצלחה')";
            return(JavaScript(js));
        }
예제 #21
0
        public ActionResult CreateMessage(EmployeeMessage item)
        {
            item.CreatedDate = DateTime.Now;
            item.CreatedBy   = new Employee
            {
                Id = GetEmployeeId
            };

            if (item.To.Id != item.CreatedBy.Id)
            {
                var employee = GetSession.Load <Employee>(item.To.Id);
                item.To = employee;

                /*	if (employee.Email.Contains("@")) {
                 *      new NotificationsController().Message(employee).Deliver();
                 *  }*/
            }
            GetSession.Save(item);

            return(RedirectToAction("Card", new { item.To.Id }));
        }
예제 #22
0
        public ActionResult Create(PageFormModel model, FormCollection coll)
        {
            var  item   = Mapper.Map <PageFormModel, Page>(model);
            Page parent = null;

            if (model.ParentId.HasValue)
            {
                parent      = GetSession.Get <Page>(model.ParentId);
                item.Parent = parent;
            }

            int maxOrder = GetSession.Query <Page>()
                           .Where(x => x.Parent == parent &&
                                  x.SectionId == model.SectionId
                                  ).Max(x => (int?)x.PageOrder) ?? 0;

            if (item.TypeId == 999)
            {
                item.PageTemplate         = "tv";
                item.Iframelink1DelayTime = coll["Iframelink1"].ToString().Split(',')[1];
                item.Iframelink2DelayTime = coll["Iframelink2"].ToString().Split(',')[1];
                item.Iframelink3DelayTime = coll["Iframelink3"].ToString().Split(',')[1];
                item.Iframelink4DelayTime = coll["Iframelink4"].ToString().Split(',')[1];
                item.Iframelink5DelayTime = coll["Iframelink5"].ToString().Split(',')[1];
            }
            if (item.TypeId == 001)
            {
            }


            item.PageOrder   = maxOrder + 1;
            item.IsInternal  = true;
            item.UpdatedDate = DateTime.Now;

            GetSession.Save(item);

            return(RedirectToAction("Index", new { model.ParentId, model.SectionId }));
        }
예제 #23
0
        public JavaScriptResult UpdateUsers(DocFormModel model, string[] users, long id)
        {
            string result = "";

            if (users != null)
            {
                if (users.Length > 0)
                {
                    result = string.Join(",", users);
                    //return Redirect("/ForumItems/");
                }
            }



            Doc forumTarget = GetSession.Get <Doc>(id);

            forumTarget.Units = result;

            GetSession.Save(forumTarget);
            string js = @"alert('עודכן בהצלחה')";

            return(JavaScript(js));
        }
예제 #24
0
        public ActionResult Take(Int64 id, PollTakeFormModel model)
        {
            Poll poll = GetSession.Get <Poll>(id);

            if (poll != null && poll.Id == CurrentPollId)
            {
                try
                {
                    Guid sessionId = Guid.NewGuid();

                    PollTaking pollTaking = new PollTaking()
                    {
                        Poll          = poll,
                        Employee      = Portal.Helpers.EmployeesHelper.GetCurrentEmployee(),
                        Department_id = CurrentPollDepartmentId.HasValue ? CurrentPollDepartmentId.Value : 0,
                        Manager       = CurrentPollManagerId.HasValue ? GetSession.Get <Employee>(CurrentPollManagerId.Value) : null,
                        SessionId     = sessionId
                    };
                    GetSession.Save(pollTaking);

                    Regex regex = new Regex(@"\[[0-9]+\]", RegexOptions.IgnoreCase);

                    foreach (string key in Request.Form.AllKeys)
                    {
                        MatchCollection matches = regex.Matches(key);

                        if (matches.Count > 0)
                        {
                            char[] charsToTrim = { '[', ']' };

                            long   itemId = Convert.ToInt64(matches[0].Value.Trim(charsToTrim));;
                            string value  = this.Request.Form[key];

                            if (!String.IsNullOrWhiteSpace(value))
                            {
                                PollItem item = GetSession.Get <PollItem>(itemId);

                                EmployeePollItem employeePollItem = GetSession.QueryOver <EmployeePollItem>()
                                                                    .Where(epi => epi.Employee.Id == Portal.Helpers.EmployeesHelper.GetCurrentEmployee().Id&&
                                                                           epi.PollItem.Id == item.Id)
                                                                    .Take(1)
                                                                    .SingleOrDefault();

                                if (employeePollItem == null || (poll.AnonymousUser != null && poll.AnonymousUser.Id == EmployeesHelper.GetCurrentEmployee().Id))
                                {
                                    employeePollItem = GetSession.QueryOver <EmployeePollItem>()
                                                       .Where(epi => epi.Employee.Id == Portal.Helpers.EmployeesHelper.GetCurrentEmployee().Id&&
                                                              epi.PollItem.Id == item.Id && epi.SessionId == sessionId)
                                                       .Take(1)
                                                       .SingleOrDefault();

                                    if (employeePollItem == null)
                                    {
                                        employeePollItem = new EmployeePollItem()
                                        {
                                            Employee = Portal.Helpers.EmployeesHelper.GetCurrentEmployee(),
                                            PollItem = item
                                        };
                                    }
                                }

                                employeePollItem.PollTaking = pollTaking;

                                // Irrelevant question
                                if (key.ToLower().Contains("irrelevant"))
                                {
                                    if (value.Equals("on", StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        employeePollItem.AnswerValue = -1;
                                    }
                                }
                                else
                                {
                                    switch (item.Type)
                                    {
                                    case QuestionType.Open:
                                        employeePollItem.AnswerText = value;
                                        break;

                                    case QuestionType.Range:
                                        employeePollItem.AnswerValue = Convert.ToInt32(Convert.ToDecimal(value));
                                        break;

                                    case QuestionType.Multiple:
                                        employeePollItem.AnswerValue = Convert.ToInt32(Convert.ToDecimal(value));
                                        switch (employeePollItem.AnswerValue)
                                        {
                                        case 1:
                                            employeePollItem.Option1Count = 1;
                                            employeePollItem.Option2Count = 0;
                                            employeePollItem.Option3Count = 0;
                                            employeePollItem.Option4Count = 0;
                                            employeePollItem.Option5Count = 0;
                                            employeePollItem.Option6Count = 0;
                                            break;

                                        case 2:
                                            employeePollItem.Option1Count = 0;
                                            employeePollItem.Option2Count = 1;
                                            employeePollItem.Option3Count = 0;
                                            employeePollItem.Option4Count = 0;
                                            employeePollItem.Option5Count = 0;
                                            employeePollItem.Option6Count = 0;
                                            break;

                                        case 3:
                                            employeePollItem.Option1Count = 0;
                                            employeePollItem.Option2Count = 0;
                                            employeePollItem.Option3Count = 1;
                                            employeePollItem.Option4Count = 0;
                                            employeePollItem.Option5Count = 0;
                                            employeePollItem.Option6Count = 0;
                                            break;

                                        case 4:
                                            employeePollItem.Option1Count = 0;
                                            employeePollItem.Option2Count = 0;
                                            employeePollItem.Option3Count = 0;
                                            employeePollItem.Option4Count = 1;
                                            employeePollItem.Option5Count = 0;
                                            employeePollItem.Option6Count = 0;
                                            break;

                                        case 5:
                                            employeePollItem.Option1Count = 0;
                                            employeePollItem.Option2Count = 0;
                                            employeePollItem.Option3Count = 0;
                                            employeePollItem.Option4Count = 0;
                                            employeePollItem.Option5Count = 1;
                                            employeePollItem.Option6Count = 0;
                                            break;

                                        case 6:
                                            employeePollItem.Option1Count = 0;
                                            employeePollItem.Option2Count = 0;
                                            employeePollItem.Option3Count = 0;
                                            employeePollItem.Option4Count = 0;
                                            employeePollItem.Option5Count = 0;
                                            employeePollItem.Option6Count = 1;
                                            break;
                                        }
                                        break;
                                    }
                                }
                                employeePollItem.SessionId = sessionId;


                                GetSession.Save(employeePollItem);
                            }
                        }
                    }
                }
                catch
                {
                }

                Session["Poll_Id"]            = null;
                Session["Poll_Department_Id"] = null;
                Session["Poll_Manager_Id"]    = null;
                Session["Poll_LCID"]          = null;

                return(View("TakeEnd", new PollTakeEndFormModel()
                {
                    Poll = poll,
                    IsRightToLeft = CurrentPollLCID.HasValue ? CultureHelper.IsRightToLeft(CurrentPollLCID.Value) : true
                }));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
예제 #25
0
        public ActionResult UpdateEmployees()
        {
            ////-----------------
            //string filePaths = @"E:\Users\max\Desktop\Development\ON AIR SITES\New Sites Online_Alex\Zoglobek PORTAL\Source\Portal.Web.UI.Application\Public\userfiles\SOGPORTAL.xlsx";


            //string strFile = @"E:\Users\max\Desktop\Development\ON AIR SITES\New Sites Online_Alex\Zoglobek PORTAL\Source\Portal.Web.UI.Application\Public\userfiles\SOGPORTAL.xlsx";

            //string strTemp = Path.GetExtension(strFile).ToLower();

            //if (strTemp == ".xls")
            //{
            //    strFile = Path.ChangeExtension(strFile, "xlsx");
            //}



            //foreach (string myfile in filePaths)
            //{
            //    filename = Path.ChangeExtension(myfile, ".txt");
            //    System.IO.File.Move(myfile, filename);
            //}


            ////------------------



            Log newLog = new Log();

            newLog.id = Guid.NewGuid();


            int    added    = 0;
            int    deleted  = 0;
            int    updated  = 0;
            int    errors   = 0;
            int    warnings = 0;
            string result   = "";


            int    logg = 0;
            string name = "";

            try
            {
                var excel = new ExcelQueryFactory();

                string[] ex_names = MvcApplication.Config("excel_name").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);



                //insert all employees from excel to temp list<>
                List <string> excel_emp_id = new List <string>();



                for (int ex_name = 0; ex_name < ex_names.Length; ex_name++)
                {
                    excel.FileName = ex_names[ex_name];

                    //employees from excel
                    var result_employees = from c
                                           in excel.WorksheetNoHeader(0)
                                           select c;



                    List <Employee> employees = new List <Employee>();



                    UpdateJobs();
                    UpdateDepartments();

                    //Dictionary
                    Dictionary <string, long> dep_dict = new Dictionary <string, long>();


                    //existing Department from db
                    List <Department> existing_deps = (List <Department>)GetSession.QueryOver <Department>().List();


                    foreach (Department dep in existing_deps)
                    {
                        dep_dict.Add(dep.Name, dep.Id);
                    }


                    //get all employees to dictinary
                    Dictionary <string, long> emps_dict = new Dictionary <string, long>();



                    Dictionary <string, long> job_dict = new Dictionary <string, long>();

                    //existing Jobs from db
                    List <JobTitle> existing_jobs = (List <JobTitle>)GetSession.QueryOver <JobTitle>().List();

                    foreach (JobTitle job in existing_jobs)
                    {
                        job_dict.Add(job.Name, job.Id);
                    }


                    Dictionary <string, string> users_managers = new Dictionary <string, string>();

                    //result_employees -> employees from excel
                    int i = 0;
                    foreach (var employee in result_employees)
                    {
                        //check for must feilds
                        if (!string.IsNullOrEmpty(employee[1].ToString().Trim()) &&
                            !string.IsNullOrEmpty(employee[2].ToString().Trim()) &&
                            !string.IsNullOrEmpty(employee[13].ToString().Trim()) &&
                            !string.IsNullOrEmpty(employee[0].ToString().Trim()))
                        {
                            logg++;
                            name = employee[0];


                            if (i > 0 && !string.IsNullOrEmpty(employee[0].ToString().Trim()))
                            {
                                //check for wanted feilds
                                if (string.IsNullOrEmpty(employee[5].ToString().Trim()) || string.IsNullOrEmpty(employee[7].ToString().Trim()))
                                {
                                    newLog.WarningLines = newLog.WarningLines + (i + 1) + ",";
                                    warnings++;
                                }

                                excel_emp_id.Add(employee[0].ToString().Trim());

                                if (employee[5] != "")
                                {
                                    users_managers.Add(employee[0], employee[5]);
                                }



                                //if employee exists in DB
                                if (GetSession.Get <Employee>(Convert.ToInt64(employee[0].ToString().Trim())) == null)
                                {
                                    //add new employee
                                    string sBirthDate = employee[7].ToString().Trim() ?? "";
                                    //string username = employee[9].ToString().Trim() == "" ?
                                    //  "New User" : employee[9].ToString().Trim().Substring(0, employee[9].ToString().Trim().ToString().IndexOf('@'));
                                    string userName = employee[0].ToString().Trim();


                                    EmployeeFormModel model = new EmployeeFormModel()
                                    {
                                        Id        = Convert.ToInt64(employee[0].ToString().Trim()),
                                        Password  = employee[0].ToString().Trim(),
                                        LastName  = employee[2].ToString().Trim(),
                                        FirstName = employee[1].ToString().Trim(),
                                        Email     = string.IsNullOrEmpty(employee[9].ToString().Trim()) ? "*****@*****.**" : employee[9].ToString().Trim(),
                                        Phone     = employee[10].ToString().Trim(),
                                        Picture   = employee[0].ToString().Trim() + ".jpg",
                                        Mobile    = employee[11].ToString().Trim(),
                                        //Manager = GetSession.Get<Employee>(Convert.ToInt64(employee[5].ToString().Trim())),
                                        Range      = employee[12].ToString().Trim(),
                                        BDay       = (employee[7].ToString().Trim() != "") ? Convert.ToDateTime(sBirthDate) : DateTime.Now,
                                        IsActive   = Convert.ToBoolean(Convert.ToInt32(employee[13].ToString().Trim())),
                                        JbTitle    = GetSession.Get <JobTitle>(job_dict.FirstOrDefault(x => x.Key == employee[8].ToString().Trim()).Value),
                                        Department = GetSession.Get <Department>(dep_dict.FirstOrDefault(x => x.Key == employee[4].ToString().Trim()).Value),
                                        Username   = userName
                                    };

                                    var item = Mapper.Map <EmployeeFormModel, Employee>(model);

                                    GetSession.Save(item);
                                    added++;

                                    // string s = job_dict.FirstOrDefault(employee[3].ToString().Trim()).Key;
                                }
                                else
                                {
                                    //update employee

                                    var    item       = GetSession.Get <Employee>(Convert.ToInt64(employee[0].ToString().Trim()));
                                    var    model      = Mapper.Map <Employee, EmployeeFormModel>(item);
                                    string sBirthDate = employee[7].ToString().Trim().ToString();

                                    string userName = employee[0].ToString().Trim();


                                    model.Password  = employee[0].ToString().Trim();
                                    model.LastName  = employee[2].ToString().Trim();
                                    model.FirstName = employee[1].ToString().Trim();
                                    model.Email     = string.IsNullOrEmpty(employee[9].ToString().Trim()) ? "*****@*****.**" : employee[9].ToString().Trim();
                                    model.Phone     = employee[10].ToString().Trim();
                                    model.Mobile    = employee[11].ToString().Trim();
                                    model.Picture   = employee[0].ToString().Trim() + ".jpg";
                                    model.Range     = employee[12].ToString().Trim();
                                    //model.Manager = GetSession.Get<Employee>(Convert.ToInt64(employee[5].ToString().Trim()));
                                    model.IsActive   = Convert.ToBoolean(Convert.ToInt32(employee[13].ToString().Trim()));
                                    model.BDay       = (employee[7].ToString().Trim() != "") ? Convert.ToDateTime(sBirthDate) : DateTime.Now;
                                    model.JbTitle    = GetSession.Get <JobTitle>(job_dict.FirstOrDefault(x => x.Key == employee[8].ToString().Trim()).Value);
                                    model.Department = GetSession.Get <Department>(dep_dict.FirstOrDefault(x => x.Key == employee[4].ToString().Trim()).Value);
                                    //model.Username = employee[9].ToString().Trim() == "" ? "" : employee[9].ToString().Trim().ToString().Substring(0, employee[9].ToString().Trim().ToString().IndexOf('@'));
                                    model.Username = userName;
                                    Mapper.Map <EmployeeFormModel, Employee>(model, item);
                                    GetSession.Update(item);
                                    updated++;
                                }
                            }
                            i++;
                        }
                        else
                        {
                            newLog.ErrorLines = newLog.ErrorLines + (i + 1) + ",";
                            errors++;
                            i++;
                        }
                    }



                    //TODO
                    //update managers
                    //UpdateManagers(users_managers);
                }



                // bring all existing employees
                List <Employee> current_employees = (List <Employee>)GetSession.QueryOver <Employee>().List();
                foreach (Employee curr_emp in current_employees)
                {
                    // if employee nof found in excel > disactivate this employee
                    if (!excel_emp_id.Contains(curr_emp.Id.ToString()))
                    {
                        if (curr_emp.Username != MvcApplication.Config("admin.Username"))
                        {
                            var item  = GetSession.Get <Employee>(curr_emp.Id);
                            var model = Mapper.Map <Employee, EmployeeFormModel>(item);
                            model.IsActive = false;
                            Mapper.Map <EmployeeFormModel, Employee>(model, item);
                            GetSession.Update(item);

                            deleted++;
                        }
                    }

                    #region 1

                    //if (curr_emp.Username == MvcApplication.Config("admin.Username"))
                    //{
                    //    var item = GetSession.Get<Employee>(curr_emp.Id);
                    //    var model = Mapper.Map<Employee, EmployeeFormModel>(item);


                    //    model.Username = "******";
                    //    model.IsAdmin = true;
                    //    model.IsActive = true;

                    //    Mapper.Map<EmployeeFormModel, Employee>(model, item);
                    //    GetSession.Update(item);
                    //}
                    #endregion
                }
            }
            catch (Exception ex)
            {
                return(Content(ex.Data + ">>>>>" + ex.InnerException + ">>>>>" + ex.Message + " >>>>>>>> line" + logg + "name =" + name));
            }
            result = string.Format("<h3>Update Results</h3><p>New : {0} </p><p>Processed : {1} </p><p>Deleted {2}</p><p>Errors {3}</p><p>Warnings {4}</p>", added, updated, deleted, errors, warnings);


            newLog.Logdate      = DateTime.Now;
            newLog.UpdatedCount = updated;
            newLog.NewEmps      = added.ToString();
            GetSession.Save(newLog);

            TempData["warnings"] = newLog.WarningLines;


            return(RedirectToAction("ProssesResult", new { added = added, updated = updated, deleted = deleted, errors = errors, warningsL = newLog.WarningLines, warnings = warnings }));
            //return Content(result, "text/html");
        }
예제 #26
0
        public ActionResult Create(ForumFormModel model, int categoryId = 1)
        {
            if (ModelState.IsValid)
            {
                #region Replace url text with link
                string body = model.Body;

                var outputString = model.Body;

                Regex regx = new Regex(@"https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?", RegexOptions.IgnoreCase);

                MatchCollection mactches = regx.Matches(model.Body);
                foreach (Match match in mactches)
                {
                    outputString = outputString.Replace(match.Value, String.Format("<a href=\"{0}\" target=\"_blank\">לחץ כאן</a>", match.Value));
                }

                body = outputString;


                model.Body = body;
                #endregion


                var item = Mapper.Map <ForumFormModel, Forum>(model);
                item.CreatedBy = new Employee
                {
                    Id = GetEmployeeId
                };

                if (model.ParentId.HasValue)
                {
                    var forum = GetSession.Load <Forum>(model.ParentId);
                    item.Parent  = forum;
                    item.Subject = item.Parent.Subject; // Must be Uniqe!!!!
                }
                ViewData["catId"] = categoryId;
                item.CategoryId   = categoryId;
                ViewBag.list      = GetSession.QueryOver <ForumItem>().List();

                GetSession.Save(item);

                var    current_domain = MvcApplication.Config("current_domain").ToString();
                string host           = HttpContext.ApplicationInstance.Request.Url.Host;


                var forumItem = GetSession.QueryOver <ForumItem>().Where(x => x.Id == categoryId).SingleOrDefault().Admin;



                #region Send mail to forum users


                if (GetSession.Get <ForumItem>(Convert.ToInt64(categoryId)).isAvailableTooAll == false)
                {
                    Employee emp;
                    var      forum_users = GetSession.Get <ForumItem>(Convert.ToInt64(categoryId)).ForumUsers;
                    string[] ids         = forum_users.Split(',');

                    var list = new List <string>(ids);
                    list.Remove(GetEmployeeId.ToString());
                    ids = list.ToArray();

                    for (int i = 0; i < ids.Length; i++)
                    {
                        long id = Convert.ToInt64(ids[i]);
                        emp = GetSession.Get <Employee>(id);
                        sendMailTo(emp, categoryId);
                    }
                }



                #endregion



                MailMessage mail = new MailMessage();
                mail.From = new MailAddress("*****@*****.**");
                mail.To.Add(forumItem.Email.ToString());
                mail.Subject    = "הודעה חדשה בפורום";
                mail.IsBodyHtml = true;
                mail.Body       = "<html><body>"
                                  + "<h1>שלום, " + forumItem.FirstName.ToString() + " !</h1>"
                                  + "<h2>הודעה חדשה בפורום</h2>"
                                  + " <a href='" + host + "/Forums/" + item.CategoryId.ToString() + "'>לחץ כאן על הקישור לכניסה לפורום</a>"
                                  + "</body></html>";

                SmtpClient smtp = new SmtpClient();
                //smtp.Send(mail);



                //SmtpClient client = new SmtpClient();
                //client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "tagmedia1234");
                //client.Port = 587;
                //client.Host = "smtp.gmail.com";
                //client.EnableSsl = true;
                //MailAddress
                //    maFrom = new MailAddress("*****@*****.**", "Sender's Name"),
                //    maTo = new MailAddress(forumItem.Email.ToString(), "Recipient's Name");
                //MailMessage mmsg = new MailMessage(maFrom.Address, maTo.Address);
                //mmsg.Body =
                //    "<html><body>"
                //    + "<h1>שלום, " + forumItem.FirstName.ToString() + " !</h1>"
                //    + "<h2>הודעה חדשה בפורום</h2>"
                //    + " <a href='" + host + "/Forums/" + item.CategoryId.ToString() + "'>לחץ כאן על הקישור לכניסה לפורום</a>"
                //    + "</body></html>";
                //mmsg.IsBodyHtml = true;
                //mmsg.Subject = "הודעה חדשה בפורום";



                long ebatnya = 0;
                if (item.Parent != null)
                {
                    ebatnya = GetSession.QueryOver <ForumItem>().Where(x => x.Id == item.Parent.CategoryId).SingleOrDefault().Admin.Id;
                }
                else
                {
                    ebatnya = GetSession.QueryOver <ForumItem>().Where(x => x.Id == item.CategoryId).SingleOrDefault().Admin.Id;
                }



                if (item.CreatedBy.Id != ebatnya)
                {
                    smtp.Send(mail);
                }

                if (item.Parent != null)
                {
                    var theIdOfFather = GetSession.QueryOver <Forum>().Where(x => x.Parent == null).And(x => x.Subject == item.Subject).SingleOrDefault();



                    var theParentIsAdmin = GetSession.QueryOver <ForumItem>().Where(x => x.Id == item.Parent.CategoryId).SingleOrDefault();

                    if (item.CreatedBy.Id == theParentIsAdmin.Admin.Id)
                    {
                        var msgBody =

                            "<html><body>"
                            + "<h1>שלום, " + theIdOfFather.CreatedBy.FirstName.ToString() + " !</h1>"
                            + "<h2>הודעה חדשה בפורום</h2>"
                            + "<a href='" + host + "/Forums/" + item.CategoryId.ToString() + "'>לחץ כאן על הקישור לכניסה לפורום</a>"
                            + "</body></html>";



                        var msgSubject = "הודעה חדשה בפורום";

                        SendForumEmail(theIdOfFather.CreatedBy.Email.ToString(), msgSubject, msgBody);
                    }
                }


                return(RedirectToAction("Index"));
            }
            ViewData["catId"] = categoryId;



            return(View(model));
        }
예제 #27
0
        public ActionResult Show(Int64 id, List <int> optionResult)
        {
            Poll poll = GetSession.Get <Poll>(id);

            for (int i = 0; i < optionResult.Count; i++)
            {
                PollItem item = poll.PollItems[i];

                //session.CreateSQLQuery(string.Format("Update {0}PollItem set Option{1}Count=Option{1}Count+1 where Id={2}",
                //  MvcApplication.Config("table.Prefix"),
                //  optionResult[i],
                //  item.Id)).ExecuteUpdate();

                Session["optionResult" + DateTime.Now.Date.ToShortDateString()] = "done";

                try
                {
                    EmployeePollItem employeePollItem = GetSession.QueryOver <EmployeePollItem>()
                                                        .Where(epi => epi.Employee.Id == Portal.Helpers.EmployeesHelper.GetCurrentEmployee().Id&&
                                                               epi.PollItem.Id == item.Id)
                                                        .SingleOrDefault();

                    string query = String.Empty;

                    if (employeePollItem == null)
                    {
                        employeePollItem = new EmployeePollItem()
                        {
                            Employee = Portal.Helpers.EmployeesHelper.GetCurrentEmployee(),
                            PollItem = item
                        };
                    }
                    switch (optionResult[i])
                    {
                    case 1:
                        employeePollItem.Option1Count = 1;
                        employeePollItem.Option2Count = 0;
                        employeePollItem.Option3Count = 0;
                        employeePollItem.Option4Count = 0;
                        employeePollItem.Option5Count = 0;
                        employeePollItem.Option6Count = 0;
                        //query = string.Format("Update {0}EmployeePollItem set Option1Count=1,Option2Count=0,Option3Count=0,Option4Count=0,Option5Count=0,Option6Count=0 where Id={1}",
                        //            MvcApplication.Config("table.Prefix"),
                        //            employeePollItem.Id);
                        break;

                    case 2:
                        employeePollItem.Option1Count = 0;
                        employeePollItem.Option2Count = 1;
                        employeePollItem.Option3Count = 0;
                        employeePollItem.Option4Count = 0;
                        employeePollItem.Option5Count = 0;
                        employeePollItem.Option6Count = 0;
                        break;

                    case 3:
                        employeePollItem.Option1Count = 0;
                        employeePollItem.Option2Count = 0;
                        employeePollItem.Option3Count = 1;
                        employeePollItem.Option4Count = 0;
                        employeePollItem.Option5Count = 0;
                        employeePollItem.Option6Count = 0;
                        break;

                    case 4:
                        employeePollItem.Option1Count = 0;
                        employeePollItem.Option2Count = 0;
                        employeePollItem.Option3Count = 0;
                        employeePollItem.Option4Count = 1;
                        employeePollItem.Option5Count = 0;
                        employeePollItem.Option6Count = 0;
                        break;

                    case 5:
                        employeePollItem.Option1Count = 0;
                        employeePollItem.Option2Count = 0;
                        employeePollItem.Option3Count = 0;
                        employeePollItem.Option4Count = 0;
                        employeePollItem.Option5Count = 1;
                        employeePollItem.Option6Count = 0;
                        break;

                    case 6:
                        employeePollItem.Option1Count = 0;
                        employeePollItem.Option2Count = 0;
                        employeePollItem.Option3Count = 0;
                        employeePollItem.Option4Count = 0;
                        employeePollItem.Option5Count = 0;
                        employeePollItem.Option6Count = 1;
                        break;
                    }

                    GetSession.Save(employeePollItem);

                    //query = string.Format("INSERT INTO [{0}EmployeePollItem] ([Employee_id],[PollItem_id],[Option{1}Count]) VALUES ({2}, {3}, {4})",
                    //  MvcApplication.Config("table.Prefix"),
                    //  optionResult[i],
                    //  Portal.Helpers.EmployeesHelper.GetCurrentEmployee().Id,
                    //  item.Id,
                    //  1);

                    //GetSession.CreateSQLQuery(query).ExecuteUpdate();
                }
                catch { }
            }

            return(RedirectToAction("PollResult", new { id = id }));
        }