public IActionResult Show(int WId) { int?logUser = HttpContext.Session.GetInt32("id"); if (logUser == null) { return(View("Index")); } User loginUser = dbContext.User.FirstOrDefault(u => u.UserId == logUser); ViewBag.loginUser = logUser; // ViewModel viewmodel = new ViewModel (); // viewmodel.NewUser = loginUser; // Wedding CurrWedding = dbContext.Wedding.FirstOrDefault (w => w.WeddingId == WId); // viewmodel.NewWedding = CurrWedding; Activitys Allguests = dbContext.Activitys.Include(a => a.Assoc_Activity).ThenInclude(a => a.User).FirstOrDefault(w => w.ActivityId == WId); ViewBag.Allguests = Allguests; Activitys Activity = dbContext.Activitys.Include(x => x.User).Include(y => y.Assoc_Activity).ThenInclude(z => z.User).FirstOrDefault(act => act.ActivityId == WId); ViewBag.Activity = Activity; ViewBag.User = User; return(View(Allguests)); }
private async Task OnExecuteCreateActivity() { var inputMsgBox = new InputMessageBox { Owner = Application.Current.MainWindow, WindowStartupLocation = WindowStartupLocation.CenterOwner, Message = "Please type in the name of the activity", Title = "Add Activity", TitleIcon = new MaterialDesignIcon(MaterialDesignIconCode.Plus) }; if (inputMsgBox.ShowDialog() != true) { return; } var name = inputMsgBox.Text; using (var cmd = await _databaseService.CreateCommand(SqlQueries.Activity.Insert)) { cmd.AddParameterWithValue("@name", name); var id = Convert.ToInt64(await cmd.ExecuteScalarAsync()); Activitys.Insert(0, new ActivityTimeSlot(id, name, 0, 0D)); } CurrentActivityName = null; }
public IActionResult Join(int aId) { System.Console.WriteLine("****************************join*****************************************"); int?logUser = HttpContext.Session.GetInt32("id"); if (logUser == null) { return(View("Index")); } ViewBag.logUser = logUser; Activitys Activity = dbContext.Activitys.Include(x => x.User).Include(y => y.Assoc_Activity).ThenInclude(z => z.User).FirstOrDefault(act => act.ActivityId == aId); ViewBag.Activity = Activity; // ViewBag.logUser = logUser; Activitys Join = dbContext.Activitys.FirstOrDefault(d => d.ActivityId == aId); User LogUser = dbContext.User.FirstOrDefault(User => User.UserId == logUser); Association NewGuest = new Association(); System.Console.WriteLine("**********" + (int)logUser + "------" + aId + "******************1join*****************************************"); NewGuest.UserId = (int)logUser; NewGuest.ActivityId = aId; System.Console.WriteLine("***************************2*join*****************************************"); dbContext.Add(NewGuest); System.Console.WriteLine("***************************3*join*****************************************"); dbContext.SaveChanges(); return(RedirectToAction("Privacy")); }
public IActionResult Cancel(int actiID) { Activitys cancel = _context.Activities.FirstOrDefault(r => r.ActivityId == actiID); _context.Activities.Remove(cancel); _context.SaveChanges(); return(Redirect("/dashboard")); }
public virtual void DeleteGoogleProduct(Activitys Activitys) { if (Activitys == null) { throw new ArgumentNullException("Activitys"); } repository.Delete(Activitys); }
public virtual void UpdateGoogleProductRecord(Activitys Activitys) { if (Activitys == null) { throw new ArgumentNullException("Activitys"); } repository.Update(Activitys); }
/// <summary> /// 建立新的投票活動 /// </summary> /// <param name="outerKey"></param> /// <param name="userToken"></param> /// <param name="groupId"></param> /// <param name="title"></param> /// <param name="description"></param> /// <param name="voteItems"></param> /// <returns></returns> public Activitys VoteCreate(int creator, string groupId, string title, string content, List <VoteItemViewModel> voteItems) { var eventId = Guid.NewGuid(); var publishDate = DateTime.UtcNow; var entity = new ActVote() { Content = content, CreateDateUtc = publishDate, Creator = creator, EventId = eventId, IsStart = false, Title = title }; var activityEntity = new Activitys() { CardisShow = true, Created = TimeData.Create(DateTime.UtcNow), CreateUser = creator, Deleted = TimeData.Create(null), Updated = TimeData.Create(null), IsActivity = true, ModuleKey = Utility.ParaCondition.ModuleType.Vote, OuterKey = eventId, Publish_Utc = publishDate, ToRoomId = groupId }; try { var vote = _uow.ActVoteRepo.VoteCreate(entity); var items = new List <ActVoteItem>(); var sort = 0; foreach (var voteitem in voteItems) { var item = new ActVoteItem() { ActVoteId = vote.Id, Content = voteitem.ChooseContent, Title = voteitem.ChooseName, Sort = sort }; items.Add(item); sort++; } var newItems = _uow.ActVoteItemRepo.CreateItems(items); var activity = _uow.ActivitysRepo.ActivityCreate(activityEntity); return(activityEntity); } catch (Exception ex) { return(null); throw ex; } }
public IActionResult RemoveUserFromActivity(int aId) { int? LoginUser = HttpContext.Session.GetInt32("id"); User LogUser = dbContext.User.FirstOrDefault(u => u.UserId == LoginUser); ViewBag.loginUser = LogUser; Activitys thisWedding = dbContext.Activitys.FirstOrDefault(w => w.ActivityId == aId); Association this_Wedding = dbContext.association.FirstOrDefault(u => u.ActivityId == aId && u.UserId == (int)LoginUser); dbContext.Remove(this_Wedding); dbContext.SaveChanges(); return(RedirectToAction("Privacy")); }
public int UpdateActivity(Activitys activity) { if (Session["user"] == null) { return(-1000); } if (!PowerDAL.HasPower((Session["user"] as Users).RoleID.Value, 8)) { return(-1001); } return(ActivitysDAL.Update(activity)); }
/// <summary> /// 新增一筆主題討論活動 /// </summary> /// <param name="circleKey"></param> /// <param name="memberId"></param> /// <param name="name"></param> /// <param name="description"></param> /// <param name="fileCount"></param> /// <param name="tagId"></param> /// <returns></returns> public ActDiscussion Add(string circleKey, int memberId, string name, string description, int fileCount, int tagId) { var db = _uow.DbContext; Guid eveId = Guid.NewGuid(); DateTime?dt = DateTime.UtcNow; var learningCircleInfo = learningCircleService.GetDetailByOuterKey(circleKey); #region // 1. 建立主題討論活動物件 var objDiscussion = new ActDiscussion() { LearningId = learningCircleInfo.Id, Name = name, EventId = eveId, CreateUser = memberId, Created = TimeData.Create(dt), Updated = TimeData.Create(null), Deleted = TimeData.Create(null), Description = description, TagId = tagId, Visibility = true, Enable = true, FileCount = fileCount }; #endregion #region // 2. 替主題討論活動建立一筆訊息物件 Activitys objAct = new Activitys() { Duration = 0, ModuleKey = ModuleType.Discussion, ToRoomId = circleKey, CreateUser = memberId, Created = TimeData.Create(dt), Updated = TimeData.Create(null), Deleted = TimeData.Create(null), OuterKey = eveId, StartDate = dt, IsActivity = true, CardisShow = true, Publish_Utc = dt }; #endregion // 3. 寫入DB db.ActDiscussion.Add(objDiscussion); db.Activitys.Add(objAct); //要先儲存Activity的內容才能生出ActivityId db.SaveChanges(); return(objDiscussion); }
public IActionResult Create(Activitys newActivity) { int?ID = HttpContext.Session.GetInt32("userinSession"); ViewBag.getUser = _context.Users.FirstOrDefault(u => u.UserId == ID); if (ModelState.IsValid) { newActivity.UserId = (int)ID; _context.Activities.Add(newActivity); _context.SaveChanges(); return(Redirect("/dashboard")); } else { return(View("Activitys")); } }
private async Task OnExecuteRemoveActivity(long activityId) { var activity = Activitys.First(x => x.ActivityId == activityId); if (MessageBox.Show(Application.Current.MainWindow, $"Do you really want to delete the activity \"{activity.ActivityName}\" and all recorded time slots?", "", MessageBoxButton.YesNo) != MessageBoxResult.Yes) { return; } using (var cmd = await _databaseService.CreateCommand(SqlQueries.Activity.Remove)) { cmd.AddParameterWithValue("@id", activityId); await cmd.ExecuteNonQueryAsync(); Activitys.RemoveWhere(x => x.ActivityId == activityId); } }
public Activitys FormData(Activitys info) { info.Id = this.Id; info.Title = this.Title; info.ReleaseDate = this.ReleaseDate; info.BeginDate = this.BeginDate; info.EndDate = this.EndDate; info.Address = this.Address; info.Tel = this.Tel; info.ActityType = this.ActityType; info.ActityState = this.ActityState; info.Imgurl = this.Imgurl; info.Conent = this.Conent; info.IsTop = this.IsTop; info.Longitude = this.Longitude; info.Dimension = this.Dimension; return(info); }
public ActivitysModel ToModel(Activitys info) { this.Id = info.Id; this.Title = info.Title; this.ReleaseDate = info.ReleaseDate; this.BeginDate = info.BeginDate; this.EndDate = info.EndDate; this.Address = info.Address; this.Tel = info.Tel; this.ActityType = info.ActityType; this.ActityState = info.ActityState; this.Imgurl = info.Imgurl; this.Conent = info.Conent; this.IsTop = info.IsTop; this.Longitude = info.Longitude; this.Dimension = info.Dimension; return(this); }
/// <summary> /// 此方法用于根据交往记录id查询 /// </summary> /// <param name="actID"></param> /// <returns></returns> public static Activitys ActivityFindByACTID(int actID) { using (SqlDataReader sdr = DBHelp.ExecuteReader("select * from activitys where ActID=@ActID", new List<SqlParameter> { new SqlParameter("@ActID", actID) })) { Activitys obj = null; if (sdr.Read()) { obj = new Activitys(); obj.ActID = actID; obj.CusID = sdr["CusID"].ToString(); obj.ActDate = sdr["ActDate"].ToString(); obj.ActAdd = sdr["ActAdd"].ToString(); obj.ActTitle = sdr["ActTitle"].ToString(); obj.ActMemo = sdr["ActMemo"].ToString(); obj.ActDesc = sdr["ActDesc"].ToString(); } return obj; } }
public IActionResult AddUserToActivity(int aId) { int?LoginUser = HttpContext.Session.GetInt32("id"); System.Console.WriteLine("*********************************************************************"); System.Console.WriteLine("***" + LoginUser + " ****** " + aId + "************************"); User LogUser = dbContext.User.FirstOrDefault(User => User.UserId == LoginUser); ViewBag.loginUser = LogUser; Activitys thisWedding = dbContext.Activitys.FirstOrDefault(w => w.ActivityId == aId); Association NewGuest = new Association(); NewGuest.UserId = LogUser.UserId; NewGuest.ActivityId = thisWedding.ActivityId; dbContext.association.Add(NewGuest); dbContext.SaveChanges(); return(RedirectToAction("Privacy")); }
/// <summary> /// 此方法用于按照客户编号查询交往记录 /// </summary> /// <param name="cusID"></param> /// <returns></returns> public static List<Activitys> ActivityFindByID(string cusID) { using (SqlDataReader sdr = DBHelp.ExecuteReader("select * from activitys where cusid=@CusID order by ActDate desc", new List<SqlParameter> { new SqlParameter("@CusID", cusID) })) { List<Activitys> list = new List<Activitys>(); while (sdr.Read()) { Activitys obj = new Activitys(); obj.ActID = Convert.ToInt32(sdr["ActID"].ToString()); obj.CusID = cusID; obj.ActDate = sdr["ActDate"].ToString(); obj.ActAdd = sdr["ActAdd"].ToString(); obj.ActTitle = sdr["ActTitle"].ToString(); obj.ActMemo = sdr["ActMemo"].ToString(); obj.ActDesc = sdr["ActDesc"].ToString(); list.Add(obj); } return list; } }
public IActionResult Delete(int WId) { int?logUser = HttpContext.Session.GetInt32("id"); if (logUser == null) { return(View("Index")); } Activitys deleteW = dbContext.Activitys.FirstOrDefault(w => w.ActivityId == WId); System.Console.WriteLine("*************************" + deleteW.UserId); if (deleteW.UserId == logUser) { dbContext.Remove(deleteW); dbContext.SaveChanges(); } else { return(View("Privacy")); } return(RedirectToAction("Privacy")); }
public Activitys GetActivitys(string query) { SetParameters(); _restRequest.Parameters.Clear(); _restClient.BaseUrl = new Uri(StringUri); _restRequest.AddHeader("Content-type", "application/json"); //-------------ACESSO POR TOKEN-------------------\\ _restClient.AddDefaultHeader("Authorization", "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes($"apikey:{AccessToken}"))); _restRequest.AddHeader("Authorization", "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes($"apikey:{AccessToken}"))); _restRequest.Resource = query; _restRequest.RequestFormat = DataFormat.Json; var result = _restClient.Get(_restRequest); Activitys activities = DeserializeActivity(result.Content); return(activities); }
public IActionResult actCre(Activitys formActivity) { if (ModelState.IsValid) { User user = _context.Users.SingleOrDefault(u => u.userId == HttpContext.Session.GetInt32("UserID")); formActivity.User = user; formActivity.duration = formActivity.duration + " " + formActivity.timemeasure; _context.Activities.Add(formActivity); _context.SaveChanges(); return(Redirect("Success")); } else { IndexView RegErrors = new IndexView() { FormActivity = formActivity, AllActivities = _context.Activities.Include(post => post.User).ToList() }; Console.WriteLine("Invalid Form Sent"); Console.WriteLine(string.Join(',', ModelState)); return(View("dashboard", RegErrors)); } }
public IActionResult NewActivitys(Activitys submission) { System.Console.WriteLine("*********************" + submission.Date); DateTime dateTime12 = Convert.ToDateTime(submission.Date); if (dateTime12 < DateTime.Now) { return(View("NewActivity")); } if (ModelState.IsValid) { int?logUser = HttpContext.Session.GetInt32("id"); submission.UserId = (int)logUser; dbContext.Add(submission); dbContext.SaveChanges(); return(RedirectToAction("Privacy")); } else { return(View("NewActivity")); } }
/// <summary> /// 此方法用于修改交往记录 /// </summary> /// <param name="obj"></param> /// <returns></returns> public static bool ActivitysEdit(Activitys obj) { List<SqlParameter> list = new List<SqlParameter> { new SqlParameter("@ActDate",DateTime.Parse(obj.ActDate)), new SqlParameter("@ActAdd", obj.ActAdd), new SqlParameter("@ActTitle", obj.ActTitle), new SqlParameter("@ActMemo", obj.ActMemo), new SqlParameter("@ActDesc", obj.ActDesc), new SqlParameter("@ActID",obj.ActID) }; return DBHelp.ExecuteCUD("update activitys set ActDate=@ActDate, ActAdd=@ActAdd, ActTitle=@ActTitle, ActMemo=@ActMemo, ActDesc=@ActDesc where ActID=@ActID", list)>0; }
/// <summary> /// 此方法用于添加新的交往记录 /// </summary> /// <param name="obj"></param> /// <returns></returns> public static bool ActivitysAdd(Activitys obj) { List<SqlParameter> list = new List<SqlParameter> { new SqlParameter("@CusID", obj.CusID), new SqlParameter("@ActAdd", obj.ActAdd), new SqlParameter("@ActDate", DateTime.Parse(obj.ActDate)), new SqlParameter("@ActTitle", obj.ActTitle), new SqlParameter("@ActMemo", obj.ActMemo), new SqlParameter("@ActDesc", obj.ActDesc) }; return DBHelp.ExecuteCUD("insert into activitys values(@CusID, @ActDate , @ActAdd, @ActTitle, @ActMemo, @ActDesc)", list) > 0; }
public static int Update(Activitys activity) { return(BaseDAL.Update(activity)); }
public IActionResult LoginProcess(ViewModel userSubmission) { // if (ModelState.IsValid) // { // If inital ModelState is valid, query for a user with provided email // var userInDb = dbContext.User.FirstOrDefault(u => u.Email == userSubmission.LoginUser.Email); // // If no user exists with provided email // if (userInDb == null) // { // // Add an error to ModelState and return to View! // ModelState.AddModelError("Email", "Invalid Email/Password"); // return View("Index"); // } // // Initialize hasher object // var hasher = new PasswordHasher<LoginUser>(); // // verify provided password against hash stored in db // var result = hasher.VerifyHashedPassword(userSubmission.LoginUser, userInDb.Password, userSubmission.LoginUser.Password); // System.Console.WriteLine("*********" + result); // // result can be compared to 0 for failure // if (hasher.VerifyHashedPassword(userSubmission.LoginUser, userInDb.Password, userSubmission.LoginUser.Password) == PasswordVerificationResult.Failed) if (ModelState.IsValid) { // If inital ModelState is valid, query for a user with provided email var userInDb = dbContext.User.FirstOrDefault(u => u.Email == userSubmission.LoginUser.Email); // If no user exists with provided email if (userInDb == null) { // Add an error to ModelState and return to View! ModelState.AddModelError("Email", "Invalid Email/Password"); return(View("Index")); } // Initialize hasher object if (userSubmission.LoginUser.Password == null) { ModelState.AddModelError("Email", "Invalid email/password"); return(View("Index")); } var hasher = new PasswordHasher <LoginUser>(); // verify provided password against hash stored in db // var result = hasher.VerifyHashedPassword (userSubmission, userInDb.Password, userSubmission.Password); // System.Console.WriteLine ("*********" + result); // result can be compared to 0 for failure if (hasher.VerifyHashedPassword(userSubmission.LoginUser, userInDb.Password, userSubmission.LoginUser.Password) == PasswordVerificationResult.Failed) { ModelState.AddModelError("Email", "Invalid email/password"); return(View("Index")); } else { HttpContext.Session.SetInt32("id", userInDb.UserId); int?logUser = HttpContext.Session.GetInt32("id"); ViewBag.logUser = logUser; List <Activitys> Allw = dbContext.Activitys.Include(p => p.User).Include(a => a.Assoc_Activity).ToList(); System.Console.WriteLine("********** " + Allw + " *******"); foreach (var a in Allw) { DateTime dateTime12 = Convert.ToDateTime(a.Date); if (dateTime12 < DateTime.Now) { Activitys deleteW = dbContext.Activitys.FirstOrDefault(w => w.ActivityId == a.ActivityId); System.Console.WriteLine("*************************" + deleteW.UserId); dbContext.Remove(deleteW); dbContext.SaveChanges(); } } return(RedirectToAction("Privacy")); } } else { return(View("Index")); } }
public static int Insert(Activitys activity) { return(BaseDAL.Insert(activity)); }
/// <summary> /// 此方法用于客户开发成功 /// </summary> /// <param name="cus">要添加的客户对象</param> /// <param name="lm">要添加的联系人对象</param> /// <param name="od">要添加的订单对象</param> /// <param name="act">要添加的交往记录对象</param> /// <returns></returns> public static bool PlanSuccess(int chanID) { Chances chan = ChancesBLL.ChanFindById(chanID); //判断销售机会是否修改成功 if (null == chan) { return false; } List<Plans> plList = PlansDAL.PlanFindByID(chanID); //判断客户开发计划是否为空 if (null == plList) { return false; } //给要添加的客户初始化值 Customers cus = new Customers(); cus.CusID = CustomersBLL.GetCusID(); cus.UserID = chan.ChanDueMan; cus.CusName = chan.ChanName; //给要添加的联系人初始化值 LinkMans lm = new LinkMans(); lm.CusID = cus.CusID; lm.LMName = chan.ChanName; lm.LMMobileNo = lm.LMOfficeNo = chan.ChanLinkTel; //给要添加的订单初始化值 Orders od = new Orders(); od.CusID = cus.CusID; od.OrderDate = "getdate()"; //给要添加的交往记录初始化值 List<Activitys> actList = new List<Activitys>(); for (int i = 0; i < plList.Count; i++) { Activitys act = new Activitys(); act.CusID = cus.CusID; act.ActDate = plList[i].PlanResultDate; act.ActTitle = plList[i].PlanResult; actList.Add(act); } return CustomersBLL.CustomerAddNew(cus) && LinkMansBLL.LinkManAddNew(lm) && OrdersBLL.OrderAddNew(od) && ActivitysBLL.ActivityAddNew(actList) && ChancesBLL.PlanSuccess(chanID); }
/// <summary> /// 新增請假單 - 預先新增假單 /// </summary> /// <param name="learningId"></param> /// <param name="isTeacher"></param> /// <param name="memberId"></param> /// <param name="leaveDateTime"></param> /// <param name="leaveCategoryId"></param> /// <param name="leaveStatus"></param> /// <param name="title"></param> /// <param name="reason"></param> /// <returns></returns> public Infrastructure.ViewModel.SignInLogViewModel Add(LearningCircle learningInfo, int memberId, Infrastructure.DataTransferObject.UploadFileModel uploadInfo, List <FileStorage> files, List <Stream> fileStreams) { var parentFolderId = string.Empty; var db = _uow.DbContext; var connectionInfo = db.Members.Find(memberId); var memberAccount = _uow.EntityRepository <Member>().GetFirst(x => x.Id == memberId); if (memberAccount == null) { return(null); } var _entity = new AttendanceLeave(); var _actEntity = new Activitys(); lock (_lock) { DateTime dt = DateTime.UtcNow; Guid eveId = Guid.NewGuid(); try { var studentLeave = db.AttendanceLeave.Where(t => t.StudId == memberId).ToList(); var checkIsLeave = new AttendanceLeave(); if (studentLeave.FirstOrDefault() != null) { checkIsLeave = studentLeave.FirstOrDefault(t => t.LeaveDate.Date == uploadInfo.LeaveDate.Date && t.Status != "40" && t.LearningId == learningInfo.Id); } else { checkIsLeave = null; } if (checkIsLeave == null) { _entity.Content = uploadInfo.Content; _entity.CreateDate = dt; _entity.Creator = memberId; _entity.EventId = eveId; _entity.LearningId = learningInfo.Id; if (uploadInfo.LeaveDate.Hour == 0) { _entity.LeaveDate = uploadInfo.LeaveDate; } else { _entity.LeaveDate = uploadInfo.LeaveDate.ToUniversalTime(); } _entity.LeaveType = uploadInfo.LeaveCategoryId; _entity.Status = QueryCondition.LeaveState.Review; _entity.StudId = memberId; _entity.Subject = uploadInfo.Title; db.AttendanceLeave.Add(_entity); _actEntity.Created = Infrastructure.Property.TimeData.Create(dt); _actEntity.Updated = Infrastructure.Property.TimeData.Create(null); _actEntity.Deleted = Infrastructure.Property.TimeData.Create(null); _actEntity.CreateUser = memberId; _actEntity.IsActivity = false; _actEntity.ModuleKey = Utility.ParaCondition.ModuleType.Leave; _actEntity.OuterKey = eveId; _actEntity.CardisShow = false; _actEntity.Publish_Utc = dt; _actEntity.ToRoomId = learningInfo.LearningOuterKey; db.Activitys.Add(_actEntity); //執行 db.SaveChanges(); } else { return(null); } } catch (Exception ex) { return(null); throw ex; } } var newFiles = fileService.UploadFiles(memberId, files, fileStreams.ToArray()); var _fileArray = new string[files.Count]; if (files.Count > 0) { //建立檔案與請假單的關聯 SetLeaveFileReferenceByFiles(_entity.Id, newFiles); } var result = new Infrastructure.ViewModel.SignInLogViewModel { EventId = _entity.EventId, OuterKeySignInLog = new Dictionary <string, SignInLog>() }; //db = new iThinkDB(); var sqlSignInActivity = db.Activitys.Where(t => t.ToRoomId.ToLower() == uploadInfo.CircleKey.ToLower() && t.ModuleKey == Utility.ParaCondition.ModuleType.SignIn && t.CardisShow == true && t.StartDate.HasValue); foreach (var _act in sqlSignInActivity) { if (_act.ActivityDate != null) { if (_act.ActivityDate.Value.ToLocalTime().Date == uploadInfo.LeaveDate.Date) { var mylog = signInLogService.GetSignInLog(Convert.ToInt32(_act.CreateUser.ToString()), _act.OuterKey, memberId); if (mylog != null) { mylog.LeaveStatus = "20"; mylog.Mode = 0; mylog.Time = DateTime.UtcNow; var outerKey = Utility.OuterKeyHelper.GuidToPageToken(_act.OuterKey); result.OuterKeySignInLog.Add(outerKey, mylog); } } } } return(result); }
/// <summary> /// 新增一筆主題討論活動 /// </summary> /// <param name="circleKey"></param> /// <param name="memberId"></param> /// <param name="name"></param> /// <param name="googleDriveFileId"></param> /// <param name="description"></param> /// <param name="fileCount"></param> /// <param name="tagId"></param> /// <returns></returns> private Infrastructure.BusinessObject.DiscussionEvent Add(string circleKey, int memberId, string name, string googleDriveFileId, string description, int fileCount, int tagId) { var db = _uow.DbContext; Guid eveId = Guid.NewGuid(); DateTime?dt = DateTime.UtcNow; int id = cacheService.GetCircle(circleKey).Id; #region // 1. 建立主題討論活動物件 var objDiscussion = new ActDiscussion() { LearningId = id, Name = name, EventId = eveId, CreateUser = memberId, Created = Infrastructure.Property.TimeData.Create(dt), Updated = Infrastructure.Property.TimeData.Create(null), Deleted = Infrastructure.Property.TimeData.Create(null), Description = description, GoogleDriveUrl = googleDriveFileId, TagId = tagId, Visibility = true, Enable = true, FileCount = fileCount }; #endregion #region // 2. 替主題討論活動建立一筆訊息物件 Activitys objAct = new Activitys() { Duration = 0, ModuleKey = Utility.ParaCondition.ModuleType.Discussion, ToRoomId = circleKey, CreateUser = memberId, Created = Infrastructure.Property.TimeData.Create(dt), Updated = Infrastructure.Property.TimeData.Create(null), Deleted = Infrastructure.Property.TimeData.Create(null), OuterKey = eveId, StartDate = dt, IsActivity = true, CardisShow = true, Publish_Utc = dt }; #endregion // 3. 寫入DB db.ActDiscussion.Add(objDiscussion); db.Activitys.Add(objAct); //要先儲存Activity的內容才能生出ActivityId db.SaveChanges(); #region // 回傳給APP的物件 var data = new Infrastructure.BusinessObject.DiscussionEvent() { ClassId = circleKey, OuterKey = eveId, Creator = memberId.ToString(), CreateDate = Convert.ToDateTime(dt) }; #endregion return(data); }
/// <summary> /// 新增一筆上傳檔案活動 /// </summary> /// <param name="circleKey"></param> /// <param name="memberId"></param> /// <param name="name"></param> /// <param name="googleDriveFileId"></param> /// <param name="folderId"></param> /// <param name="fileType"></param> /// <param name="fileSize"></param> /// <param name="fileShortImg"></param> /// <returns></returns> public Infrastructure.BusinessObject.MaterialEvent Add(string circleKey, int memberId, string name, string googleDriveFileId, string folderId, string fileType, int fileSize, string fileShortImg) { Guid eveId = Guid.NewGuid(); DateTime?dt = DateTime.UtcNow; int id = cacheService.GetCircle(circleKey).Id; using (var db = _uow.DbContext) { using (var dbTransaction = db.Database.BeginTransaction()) { try { #region // 1. 建立上傳檔案活動物件 var objMaterial = new ActMaterial() { LearningId = id, Name = name, EventId = eveId, CreateUser = memberId, Created = Infrastructure.Property.TimeData.Create(dt), Updated = Infrastructure.Property.TimeData.Create(null), Deleted = Infrastructure.Property.TimeData.Create(null), GoogleDriveFileId = googleDriveFileId, FileImgUrl = string.Format("https://drive.google.com/a/g.scenet.pccu.edu.tw/uc?id={0}&export=download", googleDriveFileId), FileLength = fileSize, FileType = fileType, GoogleDriveFolder = folderId }; #endregion #region // 2. 替上傳檔案活動建立一筆訊息物件 Activitys objAct = new Activitys() { Duration = 0, ModuleKey = Utility.ParaCondition.ModuleType.Material, ToRoomId = circleKey, CreateUser = memberId, Created = Infrastructure.Property.TimeData.Create(dt), Updated = Infrastructure.Property.TimeData.Create(null), Deleted = Infrastructure.Property.TimeData.Create(null), OuterKey = eveId, StartDate = dt, IsActivity = true, CardisShow = true, Publish_Utc = dt }; #endregion #region // 3. 建立一筆Google檔案 var objGoogle = new GoogleFile() { DownLoadUrl = string.Format("https://drive.google.com/a/g.scenet.pccu.edu.tw/uc?id={0}&export=download", googleDriveFileId), FileId = googleDriveFileId, FileType = fileType, ImgUrl = string.Format("https://drive.google.com/a/g.scenet.pccu.edu.tw/uc?id={0}&export=download", fileShortImg), WebViewUrl = string.Format("https://drive.google.com/a/g.scenet.pccu.edu.tw/file/d/{0}/view?usp=drivesdk", googleDriveFileId), Name = name, ParentFileId = folderId, Size = fileSize, Create_User = memberId, Create_Utc = Convert.ToDateTime(dt) }; #endregion // 3. 寫入DB db.ActMaterial.Add(objMaterial); db.Activitys.Add(objAct); db.GoogleFile.Add(objGoogle); db.SaveChanges(); dbTransaction.Commit(); } catch (Exception ex) { dbTransaction.Rollback(); throw ex; } } } #region // 回傳給APP的物件 var data = new Infrastructure.BusinessObject.MaterialEvent() { ClassId = circleKey, OuterKey = eveId, Creator = memberId.ToString(), CreateDate = Convert.ToDateTime(dt) }; #endregion return(data); }
/// <summary> /// 雲端版APP專用 /// </summary> /// <param name="circleKey"></param> /// <param name="token"></param> /// <param name="files"></param> /// <returns></returns> public Infrastructure.BusinessObject.MaterialEvent AddFile(string circleKey, string token, HttpFileCollection files) { var tokenService = new TokenService(); var checkToken = tokenService.GetTokenInfo(token).Result; var learningcircleService = new LearningCircleService(); var learningcircleinfo = learningcircleService.GetDetailByOuterKey(circleKey); var createDateTime = DateTime.UtcNow; if (checkToken == null) { return(null); } var fileService = new FileService(); var newFiles = fileService.UploadFile(checkToken.MemberId, files); var file = newFiles.FirstOrDefault(); if (file == null) { return(null); } try { var db = _uow.DbContext; var materialEntity = new Infrastructure.Entity.ActMaterial() { LearningId = learningcircleinfo.Id, Name = file.Name, EventId = file.FileGuid, CreateUser = checkToken.MemberId, Created = Infrastructure.Property.TimeData.Create(createDateTime), Updated = Infrastructure.Property.TimeData.Create(null), Deleted = Infrastructure.Property.TimeData.Create(null), GoogleDriveFileId = file.FileGuid.ToString("N"), FileImgUrl = string.Format("{0}api/imgFile/{1}/{2}/{3}", loginServer, file.FileGuid.ToString("N"), maxImgWidth, maxImgHeight), FileLength = file.FileSize, FileType = file.FileContentType, Visibility = true }; var activityEntity = new Activitys() { CardisShow = true, CreateUser = checkToken.MemberId, Created = Infrastructure.Property.TimeData.Create(createDateTime), Updated = Infrastructure.Property.TimeData.Create(null), Deleted = Infrastructure.Property.TimeData.Create(null), OuterKey = file.FileGuid, Publish_Utc = createDateTime, ToRoomId = circleKey, ModuleKey = Utility.ParaCondition.ModuleType.Material, StartDate = createDateTime, IsActivity = true }; db.ActMaterial.Add(materialEntity); db.Activitys.Add(activityEntity); db.SaveChanges(); } catch (Exception ex) { return(null); throw ex; } var memberService = new MemberService(); var memberInfo = memberService.UserIdToAccount(checkToken.MemberId); var response = new Infrastructure.BusinessObject.MaterialEvent() { ClassId = circleKey, CreateAccount = memberInfo.Account, Creator = memberInfo.Id.ToString(), OuterKey = file.FileGuid, CreateDate = createDateTime }; return(response); }
/// <summary> /// 新增一筆主題討論活動 /// </summary> /// <param name="circleKey"></param> /// <param name="memberId"></param> /// <param name="name"></param> /// <param name="description"></param> /// <param name="fileCount"></param> /// <param name="tagId"></param> /// <returns></returns> public Infrastructure.ViewModel.ActivitysViewModel Add(string circleKey, int memberId, string name, string description, List <Infrastructure.DataTransferObject.RequestFile> files, int tagId) { var db = _uow.DbContext; Guid eveId = Guid.NewGuid(); DateTime?dt = DateTime.UtcNow; int fileCount = files.Count(); var learningCircleInfo = learningCircleService.GetDetailByOuterKey(circleKey); #region // 1. 建立主題討論活動物件 var objDiscussion = new ActDiscussion() { LearningId = learningCircleInfo.Id, Name = name, EventId = eveId, CreateUser = memberId, Created = TimeData.Create(dt), Updated = TimeData.Create(null), Deleted = TimeData.Create(null), Description = description, TagId = tagId, Visibility = true, Enable = true, FileCount = fileCount }; #endregion #region // 2. 替主題討論活動建立一筆訊息物件 Activitys objAct = new Activitys() { Duration = 0, ModuleKey = ModuleType.Discussion, ToRoomId = circleKey, CreateUser = memberId, Created = TimeData.Create(dt), Updated = TimeData.Create(null), Deleted = TimeData.Create(null), OuterKey = eveId, StartDate = dt, IsActivity = true, CardisShow = true, Publish_Utc = dt }; #endregion // 3. 寫入DB db.ActDiscussion.Add(objDiscussion); db.Activitys.Add(objAct); //要先儲存Activity的內容才能生出ActivityId db.SaveChanges(); #region // 3. 替主題討論活動建立一筆互動物件 方便於未來做更多功能而存 if (fileCount != 0) { // 2018-03-22 yuschang 建立附加檔案 var fileStorages = fileService.GetFileStorages(memberId, files); //建立主題討論與檔案的關聯 discussionFileService.DiscussionFileReference(objDiscussion.Id, fileStorages, null); } #endregion return(activityService.SignalrResponse(circleKey, objDiscussion.EventId, ModuleType.Discussion, memberId, true)); }