public ActionResult EditFolder(CCFolder folderObj)
        {
            User userObj = (User)Session["user"];
            Account accountObj = (Account)Session["account"];
            CCFolder folderResponse;
            int folderType = folderObj.Type;

            if (ModelState.IsValid && accountObj != null)
            {
                folderObj.AccountGUID = accountObj.AccountGUID;
                folderObj.IsPaused = false;
                folderObj.isOverFlow = false;
                if (folderObj.Type == 3)
                    folderObj.isCrimeDiary = true;
                //Save Folder
                folderResponse = CCFolderRepository.SaveFolder(folderObj);

                var folders = CCFolderRepository.CCFolders.Where(guid => guid.AccountGUID == accountObj.AccountGUID).ToList();
                TempData["SelectedMenu"] = "Manage";
                TempData["SelectedSubMenu"] = "ManageFolders";

                if (folderObj.FolderID > 0)
                {
                    var fields = CCFieldRepository.CCFolderFields.Where(u => u.FolderID == folderObj.FolderID & u.AccountGUID == accountObj.AccountGUID).ToList();
                    if (fields.Count == 0)
                    {
                        //Save default field
                        List<string> needtosave = new List<string>();
                        List<CCFolderField> savedobj = new List<CCFolderField>();

                        if (folderType == 1) {
                            if (accountObj.PlanID == 1)
                            {
                                needtosave = FieldsConfigHelper.GetFieldForContactSimple();
                            }
                            else if (accountObj.PlanID == 2)
                            {
                                needtosave = FieldsConfigHelper.GetFieldForContactBusiness();
                            }
                            else
                            {
                                needtosave = FieldsConfigHelper.GetFieldForContactFull();
                            }
                        }
                        else if (folderType == 2) { needtosave = FieldsConfigHelper.GetFieldForAppointmentSimple(); }
                        else if (folderType == 3) { needtosave = FieldsConfigHelper.GetFieldForCrimeDiaryAppointment(); }
                        else { }

                        foreach (var field in needtosave)
                        {
                            CCFolderField folderField = new CCFolderField();
                            folderField.FieldName = FieldsConfigHelper.GetRealName(field);
                            folderField.FieldType = FieldsConfigHelper.GetVariableType(field);
                            folderField.FolderID = folderObj.FolderID;
                            folderField.FieldCaption = field;
                            folderField.Restriction = "none";
                            folderField.AccountGUID = accountObj.AccountGUID;
                            folderField.isActive = true;
                            savedobj.Add(folderField);
                        }

                        var resp = CCFieldRepository.SaveFolderFieldsObj(savedobj);

                    }

                    // create note into grops
                    var alreadyExist = CCGroupRepository.CCGroups.Where(fid => fid.FolderID == folderResponse.FolderID & fid.GroupName == "Note" & fid.AccountGUID == accountObj.AccountGUID).ToList();

                    if (alreadyExist.Count == 0)
                    {
                        CCGroup objGroup = new CCGroup();
                        objGroup.GroupName = "Note";
                        objGroup.FolderID = folderResponse.FolderID;
                        objGroup.AccountGUID = accountObj.AccountGUID;
                        var user = CCGroupRepository.SaveGroup(objGroup);
                    }

                    // create default group
                    var isDefaultGrpExist = CCGroupRepository.CCGroups.Where(fid => fid.FolderID == folderResponse.FolderID & fid.GroupName == "Default" & fid.AccountGUID == accountObj.AccountGUID).ToList();

                    if (isDefaultGrpExist.Count == 0)
                    {
                        // add default group
                        CCGroup objGroup = new CCGroup();
                        objGroup.GroupName = "Default";
                        objGroup.FolderID = folderResponse.FolderID;
                        objGroup.AccountGUID = accountObj.AccountGUID;
                        var grp = CCGroupRepository.SaveGroup(objGroup);

                        if (grp.GroupID != 0)
                        {
                            // added all default field
                            var defaultfields = CCFieldRepository.CCFolderFields.Where(u => u.FolderID == folderObj.FolderID & u.AccountGUID == accountObj.AccountGUID).ToList();
                            int i = 1;
                            foreach (var fieldItem in defaultfields)
                            {
                                CCGroupField objgrpfield = new CCGroupField();
                                objgrpfield.FieldID = fieldItem.FieldID;
                                objgrpfield.FieldOrder = i++;
                                objgrpfield.FolderID = grp.FolderID;
                                objgrpfield.GroupID = grp.GroupID;
                                objgrpfield.AccountGUID = accountObj.AccountGUID;
                                var aa = CCGroupFieldRepository.SaveGroupField(objgrpfield);
                            }
                        }
                    }

                    // create default layout
                    var isDefaultLayoutExist = CCLayoutRepository.CCLayouts.Where(fid => fid.FolderID == folderResponse.FolderID & fid.LayoutName == "Default" & fid.AccountGUID == accountObj.AccountGUID).ToList();

                    if (isDefaultLayoutExist.Count == 0)
                    {
                        // add default layout
                        CCLayout layout = new CCLayout();
                        layout.LayoutName = "Default";
                        layout.FolderID = folderObj.FolderID;
                        layout.AccountGUID = accountObj.AccountGUID;
                        var resLayout = CCLayoutRepository.Savelayout(layout);

                        // add default group into default layout
                        var defaultExistGrp = CCGroupRepository.CCGroups.Where(fid => fid.FolderID == folderResponse.FolderID & fid.GroupName == "Default" & fid.AccountGUID == accountObj.AccountGUID).FirstOrDefault();
                        if (defaultExistGrp != null)
                        {
                            CCLayoutGroup objLayoutGroup = new CCLayoutGroup();
                            objLayoutGroup.GroupID = defaultExistGrp.GroupID;
                            objLayoutGroup.GroupOrder = 1;
                            objLayoutGroup.FolderID = resLayout.FolderID;
                            objLayoutGroup.LayoutID = resLayout.LayoutID;
                            objLayoutGroup.AccountGUID = accountObj.AccountGUID;
                            var aa = CCLayoutGroupRepository.SavelayoutGroup(objLayoutGroup);
                        }
                    }

                }

                var folderList = CCFolderRepository.CCFolders.Where(guid => guid.AccountGUID == accountObj.AccountGUID).ToList();
                Session["folderss"] = folderList;

                LimitationsViewModel limitationsObjMain = (LimitationsViewModel)Session["limitations"];
                HelperFunctions HF = new HelperFunctions();
                limitationsObjMain = HF.updateAccountLimitations(accountObj);
                Session["limitations"] = limitationsObjMain;

                return RedirectToAction("ManageFolders", "Folder");
            }
            else
            {
                var folderList = CCFolderRepository.CCFolders.Where(guid => guid.AccountGUID == accountObj.AccountGUID).ToList();
                Session["folderss"] = folderList;

                LimitationsViewModel limitationsObjMain = (LimitationsViewModel)Session["limitations"];
                HelperFunctions HF = new HelperFunctions();
                limitationsObjMain = HF.updateAccountLimitations(accountObj);
                Session["limitations"] = limitationsObjMain;

                return View(folderObj);
            }
        }
 public ActionResult EditLayout(CCLayout layoutObj)
 {
     Account accountObj = (Account)Session["account"];
     User userObj = (User)Session["user"];
     if (ModelState.IsValid)
     {
         layoutObj.AccountGUID = accountObj.AccountGUID;
         var user = CCLayoutRepository.Savelayout(layoutObj);
         return RedirectToAction("ManageLayoutsAndGroups", "Folder", new { ID = layoutObj.FolderID });
     }
     else
     {
         return View(layoutObj);
     }
 }
        public ActionResult ManageLayoutsAndGroups(long ID)
        {
            TempData["SelectedMenu"] = "ManageFolders";
            ManageLayoutsAndGroupsViewModel manageLayoutsAndGroups = new ManageLayoutsAndGroupsViewModel();
            Account accountObj = (Account)Session["account"];

            var groups = CCGroupRepository.CCGroups.Where(u => u.FolderID == ID & u.AccountGUID == accountObj.AccountGUID).ToList();
            manageLayoutsAndGroups.Groups = groups;

            var layouts = CCLayoutRepository.CCLayouts.Where(u => u.FolderID == ID & u.AccountGUID == accountObj.AccountGUID).ToList();
            if (layouts.Count == 0)
            {
                List<CCLayout> layoutlist = new List<CCLayout>();
                CCLayout layoutobj = new CCLayout();
                layoutobj.FolderID = ID;
                layoutobj.LayoutID = 0;
                layoutobj.LayoutName = "empty";
                layoutlist.Add(layoutobj);
                manageLayoutsAndGroups.Layouts = layoutlist;
            }
            else
            {
                manageLayoutsAndGroups.Layouts = layouts;
            }

            var folderNmae = CCFolderRepository.CCFolders.Where(fid => fid.FolderID == ID & fid.AccountGUID == accountObj.AccountGUID).FirstOrDefault().Name;
            manageLayoutsAndGroups.FolderName = folderNmae;

            return View(manageLayoutsAndGroups);
        }
 public CCLayout Savelayout(CCLayout layoutObj)
 {
     context.CCLayouts.Add(layoutObj);
     context.SaveChanges();
     return layoutObj;
 }