Ejemplo n.º 1
0
        public ActionResult EditRoleConfirm(uRolePowerConfirm model, FormCollection form)
        {
            string result = "";

            if (model.uRolePowerSn != -1)
            {
                uRolePowerConfirm urpc = db.uRolePowerConfirm.Where(n => n.uRolePowerSn == model.uRolePowerSn).ToList().FirstOrDefault();
                urpc.uEachRoleMinNum  = model.uEachRoleMinNum;
                urpc.uTotlaRoleMinNum = model.uTotlaRoleMinNum;
            }
            else
            {
                int roleID             = Convert.ToInt32(form["roleID"]);
                int powerID            = Convert.ToInt32(form["powerID"]);
                int urpsn              = db.uRolePowers.Where(n => n.uRoleID == roleID && n.powerID == powerID).Select(n => n.urpSn).ToList().FirstOrDefault();
                uRolePowerConfirm urpc = new uRolePowerConfirm {
                    uRolePowerSn     = urpsn,
                    uEachRoleMinNum  = model.uEachRoleMinNum,
                    uTotlaRoleMinNum = model.uTotlaRoleMinNum
                };
                db.uRolePowerConfirm.Add(urpc);
            }
            db.SaveChanges();
            result = "角色覆核人數設定更新成功";
            return(Content(result));
        }
        public ActionResult Create([Bind(Include = "GoodID,FundID,FundAreaCode,FundTypeCode,FundCurrencyCode,FundCpyCode,ChargeFeeCode,Description,ClickRate")] FundGoods fundGoods)
        {
            if (ModelState.IsValid)
            {
                /////////////////////////////////////////////////////////////////////////////////////////////////////////
                db.FundGoods.Add(fundGoods);

                var a = (from m in db.FundMaster
                         where m.FundID == fundGoods.FundID
                         select m).FirstOrDefault();

                a.FundStatus = "Y";

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ChargeFeeCode    = new SelectList(db.ChargeFee, "ChargeFeeCode", "ChargeFeeCode", fundGoods.ChargeFeeCode);
            ViewBag.FundAreaCode     = new SelectList(db.FundArea, "FundAreaCode", "FundAreaName", fundGoods.FundAreaCode);
            ViewBag.FundCpyCode      = new SelectList(db.FundCompany, "FundCpyCode", "FundCpyName", fundGoods.FundCpyCode);
            ViewBag.FundCurrencyCode = new SelectList(db.FundCurrency, "FundCurrencyCode", "FundCurrencyName", fundGoods.FundCurrencyCode);
            ViewBag.FundID           = new SelectList(db.FundMaster, "FundID", "FundName", fundGoods.FundID);
            ViewBag.FundTypeCode     = new SelectList(db.FundType, "FundTypeCode", "FundTypeName", fundGoods.FundTypeCode);
            return(View(fundGoods));
        }
        public ActionResult Create([Bind(Include = "Articlename,Articlecontent,ArticleID")] Article article)
        {
            if (ModelState.IsValid)
            {
                db.Article.Add(article);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(article));
        }
Ejemplo n.º 4
0
        public ActionResult Create([Bind(Include = "LeavecategoryID,LeavecategoryName")] Leavecategory leavecategory)
        {
            if (ModelState.IsValid)
            {
                db.Leavecategory.Add(leavecategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(leavecategory));
        }
        public ActionResult Create([Bind(Include = "FundID,FundName,SetUpDate,Location,Custodian,FundScale,StarRank,FundStatus")] FundMaster fundMaster)
        {
            if (ModelState.IsValid)
            {
                db.FundMaster.Add(fundMaster);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(fundMaster));
        }
        public ActionResult Create([Bind(Include = "UserID,UserName")] User user)
        {
            if (ModelState.IsValid)
            {
                db.User.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Ejemplo n.º 7
0
        public ActionResult ManageAccounts(System.Web.Mvc.FormCollection form)
        {
            string      Id               = form["Id"].ToString();
            string      Email            = form["Email"].ToString();
            string      Password         = form["Password"].ToString();
            string      Name             = form["Name"].ToString();
            string      UserName         = form["UserName"].ToString();
            string      PhoneNumber      = form["PhoneNumber"].ToString();
            string      Telephone        = form["Telephone"].ToString();
            string      BirthDay         = form["BirthDay"].ToString();
            string      Country          = form["Country"].ToString();
            string      MailingAddress   = form["MailingAddress"].ToString();
            string      ResidenceAddress = form["ResidenceAddress"].ToString();
            string      Title            = form["Title"].ToString();
            AspNetUsers anu              = db.AspNetUsers.Where(n => n.Id == Id).First();

            anu.Email            = Email;
            anu.Name             = Name;
            anu.UserName         = UserName;
            anu.PhoneNumber      = PhoneNumber;
            anu.Telephone        = Telephone;
            anu.BirthDay         = Convert.ToDateTime(BirthDay);
            anu.Country          = Country;
            anu.MailingAddress   = MailingAddress;
            anu.ResidenceAddress = ResidenceAddress;
            anu.Title            = Title;
            db.SaveChanges();
            string strResult = "";

            try
            {
                UserManager.RemovePassword(Id);

                UserManager.AddPassword(Id, Password);

                //ApplicationDbContext context = new ApplicationDbContext();
                //UserStore<ApplicationUser> store = new UserStore<ApplicationUser>(context);
                //UserManager<ApplicationUser> UserManagerTmp = new UserManager<ApplicationUser>(store);
                //String userId = Id;//"<YourLogicAssignsRequestedUserId>";
                //String newPassword = Password; //"<PasswordAsTypedByUser>";
                //String hashedNewPassword = UserManagerTmp.PasswordHasher.HashPassword(newPassword);
                //ApplicationUser cUser = await store.FindByIdAsync(userId);
                //await store.SetPasswordHashAsync(cUser, hashedNewPassword);
                //await store.UpdateAsync(cUser);
                strResult = "完成";
            }
            catch (Exception ex)
            {
                strResult = "失敗" + ex;
            }

            return(Content(strResult));
        }
        public ActionResult abd()
        {
            Random random = new Random();

            for (int i = 0; i < 150; i++)
            {
                if (i % 7 == 1 || i%7 == 3)
                {
                    var v = random.Next(1, 15);
                    InterviewRecords records = new InterviewRecords();
                    records.UserID = "640335af-e64a-482c-a10a-61173a9321df";
                    records.EmployeeID = "886710ef-aaf3-408c-8a94-cc3d7e7de151";
                    records.Interviewer_Name = "陳韋光";
                    records.Interviewee_Name = "鄭依婷";
                    records.C_Type_ID = 5;
                    records.C_Location = "無";
                    records.StartTime = DateTime.Now.AddDays(-150+i);
                    records.InterviewContent = "";
                    records.CreateTime = DateTime.Now.AddDays(-150 + i +1);
                    records.LastModifyTime = DateTime.Now.AddDays(-v);

                    db.InterviewRecords.Add(records);
                }
            }
           
            db.SaveChanges();

            var a = (from n in db.InterviewRecords
                     select n).Count();
   
            return Json(a, JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 9
0
        public JsonResult DeleteEvent(int eventID)
        {
            var status = false;

            using (MSIT116APEXEntities dc = new MSIT116APEXEntities())
            {
                var v = dc.Events.Where(a => a.EventID == eventID).FirstOrDefault();
                if (v != null)
                {
                    dc.Events.Remove(v);
                    dc.SaveChanges();
                    status = true;
                }
            }
            return(new JsonResult {
                Data = new { status = status }
            });
        }
        public ActionResult UserConfirmUserPower(string needConfirmUserID, int?needConfirmPowerID, int?ConfirmResult, int?userNewsSn)
        {
            if (needConfirmUserID != "" && needConfirmPowerID.HasValue && ConfirmResult.HasValue && userNewsSn.HasValue)
            {
                ConfirmUserPowerMethod CUPM = new ConfirmUserPowerMethod();
                int?returnConfirmEndurpchSn = CUPM.UserConfirmUserPowerM(User.Identity.GetUserName(), needConfirmUserID, needConfirmPowerID.Value, ConfirmResult.Value);

                //將通知轉為核准/否決並轉到已讀
                UserNews un = db.UserNews.Where(n => n.sn == userNewsSn.Value).FirstOrDefault();
                IEnumerable <UserNewsUrls> unuie = db.UserNewsUrls.Where(n => n.UserNewsSn == userNewsSn.Value);
                un.read = true;
                string strCResult = ConfirmResult.Value == 1 ? "核准" : "否決";
                un.msgUrl = "";
                //un.msgContent += "<br/><button class='btn btn-info' disabled>" + strCResult + "</button>";
                foreach (var unu in unuie)
                {
                    db.UserNewsUrls.Remove(unu);
                }
                UserNewsUrls resultunus = new UserNewsUrls {
                    UserNewsSn    = un.sn,
                    UserNewsCSS   = "btn btn-info disabled",
                    UserNewsTitle = strCResult,
                    UserNewsUrl   = ""
                };
                db.UserNewsUrls.Add(resultunus);

                db.SaveChanges();

                if (returnConfirmEndurpchSn.HasValue)
                {
                    CUPM.ExecConfirmIsEnd(returnConfirmEndurpchSn.Value);
                }
            }
            //TODO
            return(RedirectToAction("UserMessage", "Account", new { area = "" }));
        }
        public ActionResult AddToOrder(FormCollection form)
        {
            if (Session["CartID"] == null)
            {
                return(RedirectToAction("Index", "FundOverview"));
            }
            List <ShoppingCart> cartList          = new List <ShoppingCart>();
            List <string>       checkRecordIDList = new List <string>();

            foreach (var RadioName in form.AllKeys)
            {
                string recordId = RadioName.Split('_')[1];

                if (!checkRecordIDList.Contains(recordId))
                {
                    checkRecordIDList.Add(recordId);
                }
            }
            foreach (var recordId in checkRecordIDList)
            {
                ShoppingCart shoppingcart = (from shop in db.ShoppingCart
                                             where shop.RecordID == recordId && shop.IsOrdered == false
                                             select shop).FirstOrDefault();

                shoppingcart.IsOrdered = true;
                cartList.Add(shoppingcart);
            }
            foreach (var RadioName in form.AllKeys)
            {
                string recordId = RadioName.Split('_')[1];
                foreach (ShoppingCart items in cartList)
                {
                    if (items.RecordID == recordId)
                    {
                        string value       = form[RadioName];
                        string controlName = RadioName.Split('_')[0];


                        switch (controlName)
                        {
                        case "currencyA":
                            var bankAccount = from a in fbc.GetAll()
                                              where a.TradeCurrencyCode == value
                                              select a.BankAccountID;
                            foreach (var account in bankAccount)
                            {
                                items.BankAccountID = account;
                            }

                            break;

                        case "textA":
                            int result = 0;
                            if (int.TryParse(value, out result))
                            {
                                items.TradePrice = result;
                                items.Amount     = result + (result * items.FundGoods.ChargeFee.ChargeFeePercentage / 100);
                            }

                            break;

                        case "date":
                            items.ChargeDateCode = value;

                            break;

                        case "currencyB":
                            var bankAccount2 = from a in fbc.GetAll()
                                               where a.TradeCurrencyCode == value
                                               select a.BankAccountID;
                            foreach (var account in bankAccount2)
                            {
                                items.BankAccountID = account;
                            }

                            break;

                        case "textB":
                            int result2 = 0;
                            if (int.TryParse(value, out result2))
                            {
                                items.TradePrice        = result2;
                                items.TradePricePerTime = result2 + (result2 * items.FundGoods.ChargeFee.ChargeFeePercentage / 100);
                            }

                            break;
                        }
                    }
                }

                db.SaveChanges();
            }


            return(RedirectToAction("CreatOrder"));
        }
Ejemplo n.º 12
0
        public JsonResult SaveEvent(Events e)
        {
            var status = false;

            using (MSIT116APEXEntities dc = new MSIT116APEXEntities())
            {
                var userid  = User.Identity.GetUserId();
                var intname = (from a in db.User
                               where a.nvarcharID == userid
                               select

                               a.UserID
                               ).FirstOrDefault();
                if (e.ThemeColor != "aqua")
                {
                    var intDepartmentID = (from a in db.User
                                           where a.nvarcharID == userid
                                           select

                                           a.DepartmentID
                                           ).FirstOrDefault();
                    var q2 = (from a in db.Department
                              where a.departmentID == intDepartmentID
                              select a.departmentName).FirstOrDefault();

                    var q = from a in db.User
                            where a.DepartmentID == intDepartmentID
                            select new
                    {
                        a.AspNetUsers.UserName
                    };
                    List <string> uesrname = new List <string>();

                    foreach (var item in q)
                    {
                        uesrname.Add(item.UserName);
                    }

                    for (int i = 0; i <= uesrname.Count - 1; i++)
                    {
                        NewsHub.SendMessageToUser(User.Identity.GetUserName(), uesrname[i], q2 + "新增行程", e.Description, "");
                    }
                }



                if (e.EventID > 0)
                {
                    //Update the event
                    var v = dc.Events.Where(a => a.EventID == e.EventID).FirstOrDefault();
                    if (v != null)
                    {
                        v.UserID      = intname;
                        v.Subject     = e.Subject;
                        v.Start       = e.Start;
                        v.End         = e.End;
                        v.Description = e.Description;
                        v.IsFullDay   = e.IsFullDay;
                        v.ThemeColor  = e.ThemeColor;
                    }
                }
                else
                {
                    e.UserID = intname;
                    dc.Events.Add(e);
                }

                dc.SaveChanges();
                status = true;
            }



            return(new JsonResult {
                Data = new { status = status }
            });
        }
        public IEnumerable <SelfSelectedStockListNumber_Table_AddModel> SelfSelectedStockListNumber_Table_Add(string EmpID, int ListID, string StockID)
        {
            var finallistnumber = (from s in db.SelfSelectedStockList
                                   where s.SSS_EmpID == EmpID && s.SSS_ListID == ListID
                                   orderby s.SSS_ListNumberID descending
                                   select s.SSS_ListNumberID).First();
            var stockrepeated = (from s in db.SelfSelectedStockList
                                 where s.SSS_EmpID == EmpID && s.SSS_ListID == ListID && s.SSS_StockID == StockID
                                 select s.SSS_StockID).Count();
            var listname = (from s in db.SelfSelectedStockList
                            where s.SSS_EmpID == EmpID && s.SSS_ListID == ListID
                            select s.SSS_ListName).First();

            if (finallistnumber == 0)
            {
                var update = from s in db.SelfSelectedStockList
                             where s.SSS_EmpID == EmpID && s.SSS_ListID == ListID
                             select s;

                foreach (var sss in update)
                {
                    sss.SSS_ListNumberID = 1;
                    sss.SSS_StockID      = StockID;
                }
                db.SaveChanges();
            }
            else
            {
                if (stockrepeated == 0)
                {
                    var insert = new SelfSelectedStockList();
                    insert.SSS_EmpID        = EmpID;
                    insert.SSS_ListID       = ListID;
                    insert.SSS_ListName     = listname;
                    insert.SSS_ListNumberID = (finallistnumber + 1);
                    insert.SSS_StockID      = StockID;

                    db.SelfSelectedStockList.Add(insert);
                    db.SaveChanges();
                }
            }

            IEnumerable <SelfSelectedStockListNumber_Table_AddModel> q = from sss in db.SelfSelectedStockList
                                                                         join si in db.StockInfo
                                                                         on sss.SSS_StockID equals si.SI_StockID
                                                                         where sss.SSS_EmpID == EmpID && sss.SSS_ListID == ListID
                                                                         orderby sss.SSS_ListNumberID
                                                                         select new SelfSelectedStockListNumber_Table_AddModel
            {
                SSS_ListNumberID = sss.SSS_ListNumberID,
                SSS_StockID      = sss.SSS_StockID,
                SI_StockName     = si.SI_StockName
            };

            return(q);
        }
        public ActionResult setDemoAccountDefault()
        {
            string      demoAccount = "*****@*****.**";
            AspNetUsers anu         = db.AspNetUsers.Where(n => n.UserName == demoAccount).FirstOrDefault();

            if (anu != null)
            {
                var ura = db.UserResidenceAddress.Where(n => n.Id == anu.Id).FirstOrDefault();
                if (ura != null)
                {
                    db.UserResidenceAddress.Remove(ura);
                    db.SaveChanges();
                }
                var uma = db.UserMailAddress.Where(n => n.Id == anu.Id).FirstOrDefault();
                if (uma != null)
                {
                    db.UserMailAddress.Remove(uma);
                    db.SaveChanges();
                }
                var uns = db.UserNews.Where(n => n.fromUser == anu.UserName || n.UserId == anu.UserName).ToList();
                if (uns != null)
                {
                    foreach (var un in uns)
                    {
                        IEnumerable <UserNewsUrls> unu = db.UserNewsUrls.Where(n => n.UserNewsSn == un.sn);
                        if (unu.Count() != 0)
                        {
                            db.UserNewsUrls.RemoveRange(unu);
                        }
                        IEnumerable <UserNewsConfirmList> uncl = db.UserNewsConfirmList.Where(n => n.UserNewsSn == un.sn);
                        if (uncl.Count() != 0)
                        {
                            db.UserNewsConfirmList.RemoveRange(uncl);
                        }
                    }
                    db.UserNews.RemoveRange(uns);
                }
                var uru = db.uRoleUsers.Where(n => n.uUserID == anu.UserName);
                if (uru != null)
                {
                    db.uRoleUsers.RemoveRange(uru);
                }
                var urpchs = db.uRolePowerConfirmHistory.Where(n => n.UserID == anu.UserName).ToList();
                if (urpchs.Count() > 0)
                {
                    foreach (var urpch in urpchs)
                    {
                        IEnumerable <uRolePowerConfirmHistoryConfirmData> urpchcds = db.uRolePowerConfirmHistoryConfirmData.Where(n => n.uRolePowerConfirmHistorySn == urpch.urpchSn).ToList();
                        if (urpchcds.Count() > 0)
                        {
                            foreach (var urpchcd in urpchcds)
                            {
                                IEnumerable <uRolePowerConfirmHistoryConfirmDataDetail> urpchcdds = db.uRolePowerConfirmHistoryConfirmDataDetail.Where(n => n.uRolePowerConfirmHistoryConfirmDataSn == urpchcd.urpchcdSn);
                                if (urpchcdds.Count() > 0)
                                {
                                    db.uRolePowerConfirmHistoryConfirmDataDetail.RemoveRange(urpchcdds);
                                }
                            }
                            db.uRolePowerConfirmHistoryConfirmData.RemoveRange(urpchcds);
                        }
                        IEnumerable <uRolePowerConfirmHistoryDetail> urpchds = db.uRolePowerConfirmHistoryDetail.Where(n => n.uRolePowerConfirmHistorySn == urpch.urpchSn);
                        if (urpchds.Count() > 0)
                        {
                            db.uRolePowerConfirmHistoryDetail.RemoveRange(urpchds);
                        }
                    }
                    db.uRolePowerConfirmHistory.RemoveRange(urpchs);
                }
                IsEmployee isee = db.IsEmployee.Where(n => n.UserId == anu.UserName).FirstOrDefault();
                if (isee != null)
                {
                    db.IsEmployee.Remove(isee);
                }
                var anul = db.AspNetUserLogins.Where(n => n.UserId == anu.Id).FirstOrDefault();
                if (anul != null)
                {
                    db.AspNetUserLogins.Remove(anul);
                }
                db.AspNetUsers.Remove(anu);
                db.SaveChanges();
                return(Content("以成功移除"));
            }
            IEnumerable <ShoppingCart> scs = db.ShoppingCart.ToList();

            if (scs.Count() > 0)
            {
                db.ShoppingCart.RemoveRange(scs);
                db.SaveChanges();
            }
            IEnumerable <FundOrderDetail> fod = db.FundOrderDetail.ToList();

            if (fod.Count() > 0)
            {
                db.FundOrderDetail.RemoveRange(fod);
                db.SaveChanges();
            }
            IEnumerable <FundOrder> fo = db.FundOrder.ToList();

            if (fo.Count() > 0)
            {
                db.FundOrder.RemoveRange(fo);
                db.SaveChanges();
            }
            Session["CartID"] = null;

            return(Content("沒有Demo帳號資料"));
        }
 public void Create(T _entity)
 {
     dbset.Add(_entity);
     db.SaveChanges();
 }
        public async Task <ActionResult> Register(RegisterViewModel modal, FormCollection form)
        {
            int    CityId           = 0;
            int    DistrictId       = 0;
            int    RoadId           = 0;
            string LnStr            = form["AddressRLn"];
            string AlyStr           = form["AddressRAly"];
            string NoStr            = form["AddressRNo"];
            string FStr             = form["AddressRF"];
            string RmStr            = form["AddressRRm"];
            string dontcheckgrc     = form["dontcheckgrc"];
            string dontcheckemail   = form["dontcheckemail"];
            string registerEmployee = form["registerEmployee"];
            bool   checkAddress     = false;

            if (int.TryParse(form["selectRCity"], out CityId))
            {
                if (int.TryParse(form["selectRDistrict"], out DistrictId))
                {
                    if (int.TryParse(form["selectRRoad"], out RoadId))
                    {
                        checkAddress = true;
                    }
                }
            }

            IRecaptcha <RecaptchaV2Result> recaptcha = new RecaptchaV2(new RecaptchaV2Data()
            {
                Secret = "6LfqzzcUAAAAAHgafe6oixzCCTIZOzvbPbGta8fT"
            });

            RecaptchaV2Result recaptchaResult = recaptcha.Verify();

            if ((dontcheckgrc == "on" || recaptchaResult.Success) && ModelState.IsValid && checkAddress)
            //if (ModelState.IsValid)
            {
                string CityName         = db.AddressCity.Where(n => n.Id == CityId).Select(n => n.Name).FirstOrDefault();
                string DistrictName     = db.AddressDistrict.Where(n => n.Id == DistrictId).Select(n => n.Name).FirstOrDefault();
                string RoadName         = db.AddressRoad.Where(n => n.Id == RoadId).Select(n => n.Name).FirstOrDefault();
                string ResidenceAddress = CityName + " " + DistrictName + " " + RoadName;
                if (LnStr != string.Empty)
                {
                    ResidenceAddress += " " + LnStr + "巷";
                }
                if (AlyStr != string.Empty)
                {
                    ResidenceAddress += " " + AlyStr + "弄";
                }
                if (NoStr != string.Empty)
                {
                    ResidenceAddress += " " + NoStr + "號";
                }
                if (FStr != string.Empty)
                {
                    ResidenceAddress += " " + FStr + "樓";
                }
                if (RmStr != string.Empty)
                {
                    ResidenceAddress += " " + RmStr + "室";
                }

                var user = new ApplicationUser {
                    UserName             = modal.Email
                    , Email              = modal.Email
                    , Name               = modal.Name
                    , ResidenceAddress   = ResidenceAddress
                    , IdentityCardNumber = modal.IdentityCardNumber
                    , BirthDay           = modal.BirthDay
                };
                var result = await UserManager.CreateAsync(user, modal.Password);

                if (result.Succeeded)
                {
                    AspNetUsers          anuFixData = db.AspNetUsers.Where(n => n.UserName == user.UserName).First();
                    UserResidenceAddress ura        = new UserResidenceAddress {
                        Id                = anuFixData.Id,
                        AddressCityId     = CityId,
                        AddressDistrictId = DistrictId,
                        AddressRoadId     = RoadId,
                        AddressLn         = LnStr,
                        AddressAly        = AlyStr,
                        AddressNo         = NoStr,
                        AddressF          = FStr,
                        AddressRm         = RmStr
                    };
                    db.UserResidenceAddress.Add(ura);
                    if (registerEmployee == "on")
                    {
                        IsEmployee nie = new IsEmployee {
                            UserId       = modal.Email,
                            RegisterDate = DateTime.Now
                        };
                        db.IsEmployee.Add(nie);
                    }
                    db.SaveChanges();
                    //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                    //return RedirectToAction("TestSuccessLogin", "Account");
                    if (dontcheckemail == "on")
                    {
                        anuFixData.EmailConfirmed = true;
                        db.SaveChanges();
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        return(RedirectToAction("Index", "Default", new { area = "" }));
                    }
                    var callbackUrl = await generateConfirmAccountEmail(user.Id);

#if DEBUG
                    TempData["ViewBagLink"] = callbackUrl;
#endif

                    ViewBag.Message = "請完成帳號的電子郵件認證,方可登入。";

                    return(View("Info"));
                }
            }
            return(View(modal));
        }
Ejemplo n.º 17
0
        public PartialViewResult EditRolePower(FormCollection form)
        {
            //if (!ModelState.IsValid)
            //{
            //    return PartialView(model);
            //}
            int        roleID = Convert.ToInt32(form["roleID"]);
            List <int> powers = new List <int>();

            foreach (var key in form.AllKeys)
            {
                if (key.Contains("powerID"))
                {
                    powers.Add(Convert.ToInt32(form.Get(key)));
                }
            }
            IEnumerable <uRolePowers> roleurps = db.uRolePowers.Where(n => n.uRoleID == roleID).ToList();

            foreach (uRolePowers urp in roleurps)
            {
                if (powers.Contains(urp.powerID))
                {
                    powers.Remove(urp.powerID);
                }
                else
                {
                    db.uRolePowers.Remove(urp);
                }
            }
            foreach (int powerID in powers)
            {
                uRolePowers urps = new uRolePowers {
                    uRoleID = roleID,
                    powerID = powerID
                };
                db.uRolePowers.Add(urps);
            }
            db.SaveChanges();

            ViewBag.StatusMessage = "編輯權限成功。";

            List <RoleEditPgPowers> reppsli = new List <RoleEditPgPowers>();

            foreach (uPages uPage in db.uPages.ToList())
            {
                IEnumerable <uPowers> uPowers = db.uPowers.Where(n => n.pageID == uPage.pageID).ToList();
                List <RoleEditPower>  repli   = new List <RoleEditPower>();
                foreach (uPowers ups in uPowers)
                {
                    bool hps = false;
                    if (db.uRolePowers.Where(n => n.uRoleID == roleID && n.powerID == ups.powerID).FirstOrDefault() != null)
                    {
                        hps = true;
                    }
                    RoleEditPower rep = new RoleEditPower
                    {
                        pageID           = ups.pageID,
                        powerID          = ups.powerID,
                        powerDescription = ups.powerDescription,
                        powerName        = ups.powerName,
                        hasPower         = hps
                    };
                    repli.Add(rep);
                }
                RoleEditPgPowers ppvmItem = new RoleEditPgPowers
                {
                    uPages         = uPage,
                    roleEditPowers = repli
                };
                reppsli.Add(ppvmItem);
            }
            RoleEditPowersViewModel repvm = new RoleEditPowersViewModel
            {
                roleID           = roleID,
                roleEditPgPowers = reppsli
            };

            return(PartialView(repvm));
        }