public ActionResult ViewLayout(long id, long fid, long pid) { Account accountObj = (Account)Session["account"]; string timeZone = (string)Session["timeZone"]; TempData["SelectedMenu"] = "Folder"; var itemInfor = CCItemRepository.CCContacts.Where(itmID => itmID.ItemID == id & itmID.AccountGUID == accountObj.AccountGUID).FirstOrDefault(); if (!itemInfor.isDistGroup) { LayoutsViewModel ObjViewLayouts = new LayoutsViewModel(); long noteGroupID = 0; bool isNoteShow = false; long layoutid = 1; var allLayouts = CCLayoutRepository.CCLayouts.Where(l => l.FolderID == fid & l.AccountGUID == accountObj.AccountGUID); var cou = allLayouts.Count(); if (allLayouts.Count() >= 1) { layoutid = allLayouts .FirstOrDefault().LayoutID; } var findNote = CCGroupRepository.CCGroups.FirstOrDefault(folder => folder.FolderID == fid && folder.GroupName == "Note" & folder.AccountGUID == accountObj.AccountGUID); if (findNote != null) { noteGroupID = findNote.GroupID; var isAddedNote = CCLayoutGroupRepository.CCLayoutGroups.FirstOrDefault(layout => layout.GroupID == noteGroupID && layout.LayoutID == layoutid & layout.AccountGUID == accountObj.AccountGUID); if (isAddedNote != null) { isNoteShow = true; } } ObjViewLayouts.LayoutDetails = CCGroupRepository.GetLayoutGroupsfieldsAndValues(layoutid, id, noteGroupID, timeZone); ObjViewLayouts.ContactID = id; ObjViewLayouts.FolderID = fid; ObjViewLayouts.FolderName = ((CCFolder)CCFolderRepository.CCFolders.Where(fold => fold.FolderID == ObjViewLayouts.FolderID).FirstOrDefault()).Name; ObjViewLayouts.PageID = pid; var isAvaiableNote = CCNoteRepository.CCNotes.FirstOrDefault(contid => contid.ContactID == id & contid.AccountGUID == accountObj.AccountGUID); if (isAvaiableNote != null) ObjViewLayouts.Note = isAvaiableNote.value; else ObjViewLayouts.Note = ""; ObjViewLayouts.IsNoteShow = isNoteShow; return View(ObjViewLayouts); } else { return RedirectToAction("ViewDistributionList", "Folder", new { ID = id }); } }
public ActionResult SelectedContactsFields(LayoutsViewModel objViewlayouts) { Account accountObj = (Account)Session["account"]; User userObj = (User)Session["user"]; CCFolder folderObj = (CCFolder)Session["folderDetail"]; var objvalues = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(objViewlayouts.FieldValues); var objfield = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(objViewlayouts.FieldNames); var allfolderfields = CCFieldRepository.CCFolderFields.Where(aid => aid.FolderID == objViewlayouts.FolderID & aid.AccountGUID == accountObj.AccountGUID); var fieldvalues = CCFieldValueRepository.CCFieldValues.Where(cid => cid.ItemID == objViewlayouts.ContactID & cid.AccountGUID == accountObj.AccountGUID); var notes = ""; int i = 0; foreach (var item in objvalues) { string itemValue = item; if (allfolderfields.Count() > 0 && fieldvalues.Count() > 0) { string fieldname = ""; fieldname = objfield[i]; if (fieldname == "Start" || fieldname == "End") { string format = "yyyy-MM-dd HH:mm"; DateTime startEndTime = DateTimeOffset.Parse(item).UtcDateTime; itemValue = startEndTime.ToString(format); } if(fieldname == "Notes") { notes = itemValue; } if (fieldname != "") { var fieldid = allfolderfields.FirstOrDefault(fname => fname.FieldName == fieldname).FieldID; CCFieldValue objFieldValue = new CCFieldValue(); if (fieldvalues.FirstOrDefault(fid => fid.FieldID == fieldid) != null) { var valueid = fieldvalues.FirstOrDefault(fid => fid.FieldID == fieldid).ValueID; objFieldValue.ValueID = valueid; } else { objFieldValue.LastUpdated = DateTime.UtcNow; objFieldValue.ValueID = 0; objFieldValue.FieldID = fieldid; objFieldValue.ItemID = objViewlayouts.ContactID; } objFieldValue.Value = itemValue; objFieldValue.AccountGUID = accountObj.AccountGUID; CCFieldValueRepository.SaveFieldValues(objFieldValue); } } i++; } long contactid = objViewlayouts.ContactID; if (contactid != 0) { AddDedupeViewModel dedupe = new AddDedupeViewModel(); foreach (var field in allfolderfields.ToList()) { if (folderObj != null) { if (folderObj.Type == 1) { if (field.FieldCaption == "First Name") { dedupe.FirstName = fieldvalues.ToList().Find(fid => fid.FieldID == field.FieldID).Value; } if (field.FieldCaption == "Middle Name") { dedupe.MiddleName = fieldvalues.ToList().Find(fid => fid.FieldID == field.FieldID).Value; } if (field.FieldCaption == "Last Name") { dedupe.LastName = fieldvalues.ToList().Find(fid => fid.FieldID == field.FieldID).Value; } if (field.FieldCaption == "Company") { dedupe.CompanyName = fieldvalues.ToList().Find(fid => fid.FieldID == field.FieldID).Value; } if (field.FieldCaption == "Email Address") { dedupe.Email = fieldvalues.ToList().Find(fid => fid.FieldID == field.FieldID).Value; } } else if (folderObj.Type == 2) { if (field.FieldCaption == "Subject") { dedupe.Subject = fieldvalues.ToList().Find(fid => fid.FieldID == field.FieldID).Value; } if (field.FieldCaption == "Start Time") { dedupe.StartDateTime = fieldvalues.ToList().Find(fid => fid.FieldID == field.FieldID).Value; } if (field.FieldCaption == "End Time") { dedupe.EndDateTime = fieldvalues.ToList().Find(fid => fid.FieldID == field.FieldID).Value; } } } } CCItems contact = new CCItems(); contact.ItemID = contactid; if (folderObj.Type == 1) { contact.DeDupeValue = dedupe.FirstName + "|" + dedupe.MiddleName + "|" + dedupe.LastName + "|" + dedupe.CompanyName + "|" + dedupe.Email; } else if (folderObj.Type == 2) { contact.DeDupeValue = dedupe.Subject + "|" + dedupe.StartDateTime + "|" + dedupe.EndDateTime; contact.Notes = notes; contact.TextBody = notes; } bool res = CCItemRepository.UpdateContact(contact); } return RedirectToAction("ViewLayout", "Folder", new { id = objViewlayouts.ContactID, fid = objViewlayouts.FolderID, pid = objViewlayouts.PageID }); }