public ActionResult SelectMappingFields(string fields, MappingFieldsViewModel objMappingFileds)
        {
            Account accountObj = (Account)Session["account"];
            CCFieldMapping fieldMapping = new CCFieldMapping();
            var objFields = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(fields);
            var mappingfields = CCFieldRepository.CCFolderFields.Where(fid => fid.FolderID == objMappingFileds.FolderID).ToList();

            var savedfield = CCFieldMappingsRepository.CCFieldsMapping
                           .Where(sid => sid.ConnectionID == objMappingFileds.SubscriptionID).ToList();

            if (savedfield.Count > 0)
            {
                CCFieldMappingsRepository.DeleteMappingFieldBySubscriptionID(objMappingFileds.SubscriptionID);

            }

            foreach (var mfield in objFields)
            {
                var mapfield = mappingfields.FirstOrDefault(fname => fname.FieldCaption == mfield);

                if (mapfield != null)
                {
                    fieldMapping.ConnectionID = objMappingFileds.SubscriptionID;
                    fieldMapping.FieldName = FieldsConfigHelper.GetRealName(mapfield.FieldName);
                    fieldMapping.Caption = mapfield.FieldCaption;
                    fieldMapping.MappedFieldID = mapfield.FieldID;
                    fieldMapping.AccountGUID = accountObj.AccountGUID;

                    var res = CCFieldMappingsRepository.SaveFieldMapping(fieldMapping);
                }
            }

            return RedirectToAction("ViewConnections", "Folder", new { id = objMappingFileds.FolderID });
        }
        public ActionResult SelectMappingFields(long ID, long sid)
        {
            Account accountObj = (Account)Session["account"];
            MappingFieldsViewModel mappingFields = new MappingFieldsViewModel();

            var mapFields = CCFieldRepository.CCFolderFields
                            .Where(fid => fid.FolderID == ID & fid.AccountGUID == accountObj.AccountGUID).ToList();

            var userToedit = mapFields;

            var savedFields = CCFieldMappingsRepository.CCFieldsMapping
                             .Where(ssid => ssid.ConnectionID == sid & ssid.AccountGUID == accountObj.AccountGUID).ToList();

            List<string> savedfieldsname = new List<string>();

            foreach (var sav in savedFields)
            {
                // add added fields name
                var resfield = mapFields.FirstOrDefault(fid => fid.FieldID == sav.MappedFieldID);
                if (resfield != null)
                {
                    savedfieldsname.Add(resfield.FieldCaption);
                }

                // remove added fields
                userToedit.RemoveAll(exist => exist.FieldID == sav.MappedFieldID);
            }

            mappingFields.AllMappingFields = userToedit.Select(fname => fname.FieldCaption).ToList();
            mappingFields.FolderID = ID;
            mappingFields.SubscriptionID = sid;
            mappingFields.SavedMappingFields = savedfieldsname;
            return View(mappingFields);
        }