public ActionResult SelectFolder(SelectFolderViewModel model)
        {
            User userObj = (User)Session["user"];
            if (!string.IsNullOrEmpty(model.SelectedFolderId))
            {
                var f = new CorporateContacts.Domain.Entities.Folder();
                f.AccountID = userObj.AccountID;
                f.SourceID = model.SelectedFolderId;
                f.IsMaster = true;
                f.SourceName = model.SelectedFolderOwnerInfo;
                f.SourceType = "Exchange";
                f.FolderName = model.SelectedFolderName;
                f.FolderType = "Contact";
                f.IsMaster = model.AddingPrimary;
                f = folderRepository.SaveFolder(f);

                if (!model.AddingPrimary)
                {
                    //add the subscription
                    var s = new Subscription();
                    s.AccountID = userObj.AccountID;
                    s.AllowAdditions = model.AllowAdditions;
                    s.IgnoreExisting = model.IgnoreExisting;
                    s.SubscriberID = f.ID;
                    s.PrimaryID = model.PrimarySourceId;
                    folderRepository.SaveSubscription(s);
                    //create the matching folderfields for the subsciption.
                    var folderFieldsForPrimary = ffRepository.FolderFields.Where(x => (x.AccountID == userObj.AccountID) && (x.FolderID == model.PrimarySourceId));
                    foreach (var ff in folderFieldsForPrimary.ToList())
                    {
                        var ffObj = FieldsConfigHelper.CreateFolderFieldFromName(ff.FName);
                        ffObj.FolderID = f.ID;
                        ffObj.AccountID = userObj.AccountID;
                        ffObj.MappedFieldID = ff.ID;
                        ffRepository.SaveFolderField(ffObj);
                    }
                    return RedirectToAction("SetupSync", "Admin", new { primarySourceID = model.PrimarySourceId });
                }
                Session["selectedFolderID"] = f.ID;
                return RedirectToAction("selectfields");
            }
            return View(new List<TreeViewFolder>());
        }
Exemplo n.º 2
0
 public Subscription SaveSubscription(Subscription subscription)
 {
     if (subscription.ID == 0)
     {
         context.Subscriptions.Add(subscription);
         context.SaveChanges();
     }
     return subscription;
 }