public JsonResult Create([FromBody] IssueLogListingModelForAjax issueLogListingModel) { if (ModelState.IsValid) { List <string> involvedPersonIds = new List <string>(); if (!string.IsNullOrEmpty(issueLogListingModel.IssueLogInvolvedPersonIds)) { involvedPersonIds = issueLogListingModel.IssueLogInvolvedPersonIds.Split(',').ToList(); } var userId = _userManager.GetUserId(User); var user = _userManager.FindByIdAsync(userId).Result; var involvedPersons = new List <ApplicationUser>(); if (involvedPersonIds.Count() > 0) { involvedPersons = _userManager.Users.Where(x => involvedPersonIds.Contains(x.Id)).ToList(); } involvedPersons.Add(user); var issueLog = BuildIssueLogForCreate(issueLogListingModel, user, involvedPersons); _issueLogService.Create(issueLog); foreach (var p in issueLog.IssueLogInvolvedPersons.Where(x => x.InvolvedPerson.Id != user.Id)) { var notification = new Notification { UserFrom = user.Id, UserFromImage = user.ProfileImageUrl, UserTo = p.InvolvedPerson.Id, Header = issueLog.Project.Name + "(" + issueLog.Project.Company.Name + ")", Message = issueLog.Header, IsRead = false }; _notificationService.Create(notification); } //var smtpClient = new SmtpClient //{ // Host = "smtp.gmail.com", // set your SMTP server name here // Port = 587, // Port // EnableSsl = true, // Credentials = new NetworkCredential("*****@*****.**", "SBsb@@##942681992fuckyouGetVirusSBsb@@##942681992fuckyou") //}; //using (var message = new MailMessage("*****@*****.**", "*****@*****.**") //{ // Subject = "Subject", // Body = "Body" //}) //{ // smtpClient.SendMailAsync(message); //} return(Json(new { redirectTo = Url.Action("Index", "IssueLog") })); } return(Json(new { redirectTo = Url.Action("Index", "IssueLog"), })); }
public JsonResult Edit([FromBody] IssueLogListingModelForAjax issueLogListingModel) { if (ModelState.IsValid) { List <string> involvedPersonIds = new List <string>(); if (!string.IsNullOrEmpty(issueLogListingModel.IssueLogInvolvedPersonIds)) { involvedPersonIds = issueLogListingModel.IssueLogInvolvedPersonIds.Split(',').ToList(); } var userId = _userManager.GetUserId(User); var user = _userManager.FindByIdAsync(userId).Result; var involvedPersons = new List <ApplicationUser>(); involvedPersons.Add(user); if (involvedPersonIds.Count() > 0) { var persons = _userManager.Users.Where(x => involvedPersonIds.Contains(x.Id)).ToList(); involvedPersons.AddRange(persons); } var issueLog = BuildIssueLogForCreate(issueLogListingModel, user, involvedPersons.Distinct()); issueLog.Id = issueLogListingModel.Id; var il = _issueLogService.GetById(issueLog.Id); bool isAllComplted = false; bool.TryParse(issueLogListingModel.IsAllCompletedExceptOwn, out isAllComplted); foreach (var item in issueLog.IssueLogInvolvedPersons) { if (item.InvolvedPerson.Id == _userManager.GetUserId(User)) { if (isAllComplted) { item.IsComplete = true; item.HoursToComplete = issueLogListingModel.WorkHour; item.SubmitDate = DateTime.Now; } } else { var searchItemFromInvolvedPerson = il.IssueLogInvolvedPersons.Where(x => x.InvolvedPerson.Id == item.InvolvedPerson.Id).FirstOrDefault(); item.HoursToComplete = searchItemFromInvolvedPerson != null ? searchItemFromInvolvedPerson.HoursToComplete : 0; item.ExpectedHour = searchItemFromInvolvedPerson != null? searchItemFromInvolvedPerson.ExpectedHour : 0; item.ReceiveDate = searchItemFromInvolvedPerson != null? searchItemFromInvolvedPerson.ReceiveDate : DateTime.MinValue; item.IsComplete = searchItemFromInvolvedPerson != null? searchItemFromInvolvedPerson.IsComplete : false; item.SubmitDate = searchItemFromInvolvedPerson != null ? searchItemFromInvolvedPerson.SubmitDate : DateTime.MinValue; } } _issueLogService.Edit(issueLog); return(Json(new { redirectTo = Url.Action("Index", "IssueLog") })); } return(Json(new { redirectTo = Url.Action("Index", "IssueLog"), })); }
private IssueLog BuildIssueLogForCreate(IssueLogListingModelForAjax model, ApplicationUser applicationUser, IEnumerable <ApplicationUser> involvedPersons) { bool isAllComplted = false; bool.TryParse(model.IsAllCompletedExceptOwn, out isAllComplted); var issueLog = new IssueLog { Project = BuildProject(int.Parse(model.ProjectId)), IssueDate = DateTime.Parse(model.IssueDate), Header = model.Header, Body = model.Body, Note = model.Note, EntryBy = applicationUser, AssignDate = DateTime.Now, IssueLogInvolvedPersons = BuildIssueLogInvolvedPerson(involvedPersons, isAllComplted), Priority = (EnumIssuePriority)int.Parse(model.Priority), TaskHour = double.Parse(model.TaskHour), IssueType = (EnumIssueType)int.Parse(model.IssueType) }; return(issueLog); }