public ActionResult RemoveUserMessage(UserNews model) { string result = ""; //檢查員工 if (cm.checkIsEmployee(User.Identity.GetUserName())) { //檢查權限刪除通知的權限ID為5 if (cm.checkHasPower(User.Identity.GetUserName(), 5)) { //檢查覆核 UserNews userNews = db.UserNews.Find(model.sn); List <UserNewsUrls> userNewsUrls = db.UserNewsUrls.Where(n => n.UserNewsSn == model.sn).ToList(); string userName = db.AspNetUsers.Where(n => n.UserName == userNews.fromUser).Select(n => n.Name).First(); string confirmDescription = ""; confirmDescription += "<div style='border:1px solid black;margin: 2px'>"; confirmDescription += "<p>欲移除通知:</p>"; confirmDescription += "<div style='border:1px solid black;margin: 2px'>"; confirmDescription += "<p>寄送者:" + userName + "<" + userNews.fromUser + ">" + "</p>"; confirmDescription += "<p>標題:" + userNews.msgTitle + "</p>"; confirmDescription += "<p>內容:" + userNews.msgContent + "</p>"; confirmDescription += "<p>發送時間:" + userNews.time + "</p>連結:"; confirmDescription += "<a href='" + userNews.msgUrl + "' class='btn btn-success'>連結</a>"; foreach (var unus in userNewsUrls) { confirmDescription += "<a href='" + unus.UserNewsUrl + "' class='" + unus.UserNewsCSS + "'>" + unus.UserNewsTitle + "</a>"; } confirmDescription += "</div>"; confirmDescription += "</div>"; int? outurpchSn; string ckConfirm = cm.checkNeedConfirm(out outurpchSn, User.Identity.GetUserName(), 5, Url.Action("UserConfirmUserPower", "ConfirmUserPower", new { area = "" }), confirmDescription); if (ckConfirm == "") { //UserNews userNews = db.UserNews.Find(model.sn); if (userNews.UserId == User.Identity.GetUserName()) { IEnumerable <UserNewsUrls> unus = db.UserNewsUrls.Where(n => n.UserNewsSn == userNews.sn); foreach (var unu in unus) { db.UserNewsUrls.Remove(unu); } db.UserNews.Remove(userNews); db.SaveChanges(); } } else { result = ckConfirm; if (outurpchSn.HasValue) { string tableName1 = ""; string primaryColumnName1 = ""; string primaryColumnValue1 = ""; SaveExecConfirmDataModelActionEnum execAction1; string primaryColumnType1 = ""; List <SaveExecConfirmDataModel> cecdm2 = new List <SaveExecConfirmDataModel>(); //UserNews userNews = db.UserNews.Find(model.sn); tableName1 = "UserNews"; primaryColumnName1 = "sn"; primaryColumnValue1 = userNews.sn.ToString(); execAction1 = SaveExecConfirmDataModelActionEnum.Remove; primaryColumnType1 = "int"; List <string> cColumnEmtry = new List <string>(); if (userNews.UserId == User.Identity.GetUserName()) { IEnumerable <UserNewsUrls> unus = db.UserNewsUrls.Where(n => n.UserNewsSn == userNews.sn); foreach (var unu in unus) { string tableName2 = "UserNewsUrls"; string primaryColumnName2 = "UserNewsUrlsID"; string primaryColumnValue2 = unu.UserNewsUrlsID.ToString(); SaveExecConfirmDataModelActionEnum execAction2 = SaveExecConfirmDataModelActionEnum.Remove; string primaryColumnType2 = "int"; SaveExecConfirmDataModel cecdm2t = new SaveExecConfirmDataModel { urpchSn = outurpchSn.Value, tableName = tableName2, primaryColumnName = primaryColumnName2, primaryColumnValue = primaryColumnValue2, primaryColumnType = primaryColumnType2, execAction = execAction2, cColumnName = cColumnEmtry, cColumnValue = cColumnEmtry, cColumnType = cColumnEmtry }; cecdm2.Add(cecdm2t); } } cm.SaveExecConfirmData(cecdm2); SaveExecConfirmDataModel cecdm1 = new SaveExecConfirmDataModel { urpchSn = outurpchSn.Value, tableName = tableName1, primaryColumnName = primaryColumnName1, primaryColumnValue = primaryColumnValue1, primaryColumnType = primaryColumnType1, execAction = execAction1, cColumnName = cColumnEmtry, cColumnValue = cColumnEmtry, cColumnType = cColumnEmtry }; cm.SaveExecConfirmData(cecdm1); } } } else { result = "沒有權限"; } } else { UserNews userNews = db.UserNews.Find(model.sn); if (userNews.UserId == User.Identity.GetUserName()) { bool checkUrls = true; while (checkUrls) { UserNewsUrls unus = db.UserNewsUrls.Where(n => n.UserNewsSn == userNews.sn).FirstOrDefault(); if (unus != null) { db.UserNewsUrls.Remove(unus); } else { checkUrls = false; } } db.UserNews.Remove(userNews); db.SaveChanges(); } } return(Content(result)); }
public PartialViewResult ChangeUserPersonData(ProcedureGetUserData_Result modal, HttpPostedFileBase Photo) { if (!ModelState.IsValid) { return(PartialView(modal)); } AspNetUsers user = db.AspNetUsers.Find(User.Identity.GetUserId()); user.Country = modal.Country; user.MailingAddress = modal.MailingAddress; user.PhoneNumber = modal.PhoneNumber; user.Telephone = modal.Telephone; string result = ""; if (Photo != null) { //檢查員工 if (cm.checkIsEmployee(User.Identity.GetUserName())) { //檢查權限更新頭像的權限ID為1 if (cm.checkHasPower(User.Identity.GetUserName(), 1)) { byte[] Tmpphotobytes = new byte[Photo.InputStream.Length]; Photo.InputStream.Read(Tmpphotobytes, 0, Tmpphotobytes.Length); ConfirmPhoto cp = new ConfirmPhoto { Photo = Tmpphotobytes }; db.ConfirmPhoto.Add(cp); db.SaveChanges(); //檢查覆核 string userUserName = User.Identity.GetUserName(); string userName = User.Identity.Name; string confirmDescription = ""; confirmDescription += "<div style='border:1px solid black;margin: 2px'>"; confirmDescription += "<p>欲更新頭像:</p>"; confirmDescription += "<div style='border:1px solid black;margin: 2px'>"; confirmDescription += "<img src='" + Url.Action("GetConfirmImageFile", "Manage", new { area = "" }) + "?pid=" + cp.Id + "' style='height:200px;width:200px;border-radius:50%'/>"; confirmDescription += "</div>"; confirmDescription += "</div>"; int? outurpchSn; string ckConfirm = cm.checkNeedConfirm(out outurpchSn, User.Identity.GetUserName(), 1, Url.Action("UserConfirmUserPower", "ConfirmUserPower", new { area = "" }), confirmDescription); //string ckConfirm = ""; if (ckConfirm == "") { //byte[] photobytes = new byte[Photo.InputStream.Length]; //Photo.InputStream.Read(photobytes, 0, photobytes.Length); user.Photo = Tmpphotobytes; } else { result = ckConfirm; //string base64 = Convert.ToBase64String(bytes); //byte[] bytes = Convert.FromBase64String(base64); if (outurpchSn.HasValue) { //byte[] photobytes = new byte[Photo.InputStream.Length]; //Photo.InputStream.Read(photobytes, 0, photobytes.Length); //string PhotoByteStr = Convert.ToBase64String(photobytes); StringBuilder PhotoByteStr = new StringBuilder(); foreach (byte pbtmp in Tmpphotobytes) { StringBuilder ppptmp = new StringBuilder(); ppptmp.Append(pbtmp); ppptmp.Append(","); PhotoByteStr.Append(ppptmp.ToString()); } string tableName1 = ""; string primaryColumnName1 = ""; string primaryColumnValue1 = ""; SaveExecConfirmDataModelActionEnum execAction1; string primaryColumnType1 = ""; List <SaveExecConfirmDataModel> cecdm2 = new List <SaveExecConfirmDataModel>(); tableName1 = "AspNetUsers"; primaryColumnName1 = "Id"; primaryColumnValue1 = User.Identity.GetUserId(); execAction1 = SaveExecConfirmDataModelActionEnum.Update; primaryColumnType1 = "string"; List <string> cColumnName = new List <string>(); List <string> cColumnValue = new List <string>(); List <string> cColumnType = new List <string>(); cColumnName.Add("Photo"); cColumnValue.Add(PhotoByteStr.ToString()); cColumnType.Add("Byte[]"); SaveExecConfirmDataModel cecdm1 = new SaveExecConfirmDataModel { urpchSn = outurpchSn.Value, tableName = tableName1, primaryColumnName = primaryColumnName1, primaryColumnValue = primaryColumnValue1, primaryColumnType = primaryColumnType1, execAction = execAction1, cColumnName = cColumnName, cColumnValue = cColumnValue, cColumnType = cColumnType }; cm.SaveExecConfirmData(cecdm1); } } } else { result = "沒有權限"; } } else { byte[] photobytes = new byte[Photo.InputStream.Length]; Photo.InputStream.Read(photobytes, 0, photobytes.Length); user.Photo = photobytes; } } db.SaveChanges(); //dbUser.UpdateWithoutNull(user); if (db.IsEmployee.Find(User.Identity.GetUserName()) != null) { ViewBag.AccountType = "員工"; } else { ViewBag.AccountType = "會員"; } var userdata = db.ProcedureGetUserData(User.Identity.GetUserId()).First(); if (result != "") { TempData["AlertConfirm"] = result; } return(PartialView(userdata)); }