public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,Phone,Email,Password,NotifyByEmail,NotifyBySMS,AboutMe,CommunityId")] Member member, HttpPostedFileBase file) { try { if (file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); fileName = DateTime.Now.ToFileTimeUtc().ToString() + "_" + fileName; var path = Path.Combine(Server.MapPath("~/img/members"), fileName); file.SaveAs(path); var serverPath = "/img/members/" + fileName; member.ImgSrc = serverPath; } ViewBag.Message = "Upload successful"; //return RedirectToAction("Index"); } catch { ViewBag.Message = "Upload failed"; member.ImgSrc = ""; //return RedirectToAction("Uploads"); } if (ModelState.IsValid) { db.Entry(member).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CommunityId = new SelectList(db.Communities, "Id", "Name", member.CommunityId); return(View(member)); }
public ActionResult Edit([Bind(Include = "Id,Name,StartTime,EndTime,Description,Budget,Status,Priority,Flag,MemberId")] MemberTask memberTask) { if (ModelState.IsValid) { db.Entry(memberTask).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MemberId = new SelectList(db.Members, "Id", "FirstName", memberTask.MemberId); return(View(memberTask)); }
public ActionResult Edit([Bind(Include = "Id,Name,Zip,Email,Password,GoogleMap")] Location location, IEnumerable <HttpPostedFileBase> files) { var imgFiles = files.ToList(); string imgSrc = ""; foreach (var file in imgFiles) { try { if (file.ContentLength > 0 && file.FileName != null) { var fileName = Path.GetFileName(file.FileName); fileName = DateTime.Now.ToFileTimeUtc().ToString() + "_" + fileName; var path = Path.Combine(Server.MapPath("~/img/locations"), fileName); file.SaveAs(path); var serverPath = "/img/locations/" + fileName; imgSrc += serverPath + ";"; location.ImgSrc = imgSrc; } ViewBag.Message = "Upload successful"; //return RedirectToAction("Index"); } catch { ViewBag.Message = "Upload failed"; //location.ImgSrc = ""; //return RedirectToAction("Uploads"); } } if (ModelState.IsValid) { db.Entry(location).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(location)); }
public ActionResult Edit([Bind(Include = "Id,Name,StartTime,EndTime,Description,Budget,Status,Priority,Flag,CommunityId")] CommunityTask communityTask) { var x1 = db.Communities; var x2 = x1.Where(i => i.Id == communityTask.CommunityId); var x3 = x2.Select(e => e.Email); var fromCommunityAddress = x3.FirstOrDefault(); var x4 = x2.Select(n => n.Name); var fromCommunityName = x4.FirstOrDefault(); var fromAddress = new MailAddress(fromCommunityAddress, fromCommunityName); string fromPassword = db.Communities .Where(i => i.Id == communityTask.CommunityId) .Select(p => p.Password). FirstOrDefault() .ToString(); string subject = communityTask.Name; string taskType; if (communityTask.Flag == true) { taskType = "task"; } else { taskType = "alert"; } string notificationBody = "Community \"" + fromCommunityName + "\" posted new " + taskType + ":\n"; notificationBody += "You can see that on <a href='/location'>"; var toMembersEmailList = db.Members .Where(i => i.CommunityId == communityTask.CommunityId) .Where(n => n.NotifyByEmail == true) .Select(e => e.Email) .ToList(); var toNameList = db.Members .Where(i => i.CommunityId == communityTask.CommunityId) .Where(n => n.NotifyByEmail == true) .Select(n => n.LastName) .ToList(); for (int index = 0; index < toMembersEmailList.Count; index++) { string toEmail = toMembersEmailList[index]; string toName = toNameList[index]; if (toEmail != null) { var toAddress = new MailAddress(toEmail, toName); var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = notificationBody }) { smtp.Send(message); } } } //Sending SMS notification if flag is true SharpGoogleVoice myAcc = new SharpGoogleVoice(fromCommunityAddress, fromPassword); var toNumbersList = db.Members .Where(i => i.CommunityId == communityTask.CommunityId) .Where(n => n.NotifyBySMS == true) .Select(p => p.Phone) .ToList(); for (int index = 0; index < toNumbersList.Count; index++) { string toNumber = "+"; toNumber += toNumbersList[index].ToString(); myAcc.SendSMS(toNumber, notificationBody); } if (ModelState.IsValid) { db.Entry(communityTask).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CommunityId = new SelectList(db.Communities, "Id", "Name", communityTask.CommunityId); return(View(communityTask)); }
public ActionResult Edit([Bind(Include = "Id,Name,StartTime,EndTime,Description,Budget,Status,Priority,Flag,LocationId")] LocationTask locationTask) { var x1 = db.Locations; var x2 = x1.Where(i => i.Id == locationTask.LocationId); var x3 = x2.Select(e => e.Email); var fromLocationAddress = x3.FirstOrDefault(); var x4 = x2.Select(n => n.Name); var fromLocationName = x4.FirstOrDefault(); var x5 = db.Members; var x6 = db.Communities; var fromAddress = new MailAddress(fromLocationAddress, fromLocationName); string fromPassword = db.Locations .Where(i => i.Id == locationTask.LocationId) .Select(p => p.Password). FirstOrDefault() .ToString(); string subject = locationTask.Name; string taskType; if (locationTask.Flag == true) { taskType = "task"; } else { taskType = "alert"; } string body = "Location \"" + fromLocationName + "\" just edited its " + taskType + ":\n"; body += "You can see that on <a href='/location'>"; var toCommunityEmailList = db.Communities.Where(i => i.LocationId == locationTask.LocationId).Select(e => e.Email).ToList(); var toNameList = db.Communities.Where(i => i.LocationId == locationTask.LocationId).Select(n => n.OfficerName).ToList(); for (int index = 0; index < toCommunityEmailList.Count; index++) { string toEmail = toCommunityEmailList[index]; string toName = toNameList[index]; if (toEmail != null) { var toAddress = new MailAddress(toEmail, toName); var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) { smtp.Send(message); } } } if (ModelState.IsValid) { db.Entry(locationTask).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.LocationId = new SelectList(db.Locations, "Id", "Name", locationTask.LocationId); return(View(locationTask)); }