public void CheckAcccountStatus(Account accountObj)
        {
            var folderList = CCFolderRepository.CCFolders.Where(f => f.AccountGUID == accountObj.AccountGUID).ToList();

            accountObj.isOverFlow = false;

            foreach (var fold in folderList)
            {
                int FolderItemCount = CCItemRepository.CCContacts.Where(i => i.FolderID == fold.FolderID).Count();

                LimitationsViewModel limitationsObj = new LimitationsViewModel();
                HelperFunctions HF = new HelperFunctions();
                limitationsObj = HF.updateAccountLimitations(accountObj);

                if ((FolderItemCount > limitationsObj.maxItemCountPerFolder) | (fold.isOverFlow == true))
                {
                    accountObj.isOverFlow = true;
                }
            }
            accountRepo.SaveAccount(accountObj);
        }
        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 DeleteSubscriptions(long id)
        {
            Account accountObj = (Account)Session["account"];
            var selectedSubscription = CCConnectinRepository.CCSubscriptions.Where(sid => sid.ConnectionID == id & sid.AccountGUID == accountObj.AccountGUID).FirstOrDefault();
            bool resp = false;
            if (selectedSubscription != null)
            {
                resp = CCConnectinRepository.DeleteSubscription(id);
            }

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

            if(resp)
                return Json("success", JsonRequestBehavior.AllowGet);
            else
                return Json("fail", JsonRequestBehavior.AllowGet);

            //return RedirectToAction("ViewConnections", "Folder", new { id = selectedSubscription.FolderID });
        }
        public ActionResult DeleteContact(long id, long fid, long pid)
        {
            bool res = false;
            Account accountObj = (Account)Session["account"];

            var allFields = CCFieldValueRepository.CCFieldValues.Where(cid => cid.ItemID == id & cid.AccountGUID == accountObj.AccountGUID).ToList();

            if (allFields.Count > 0)
            {
                foreach (var cid in allFields)
                {
                    // res = CCFieldValueRepository.DeleteFieldValue(cid.ValueID);
                }
            }

            var contact = CCItemRepository.CCContacts.Where(cid => cid.ItemID == id & cid.AccountGUID == accountObj.AccountGUID).FirstOrDefault().ItemID;

            if (contact != null)
            {
                bool deletecontact = CCItemRepository.DeleteContact(contact);
            }

            var folderDetails = CCFolderRepository.CCFolders.FirstOrDefault(f => f.FolderID == fid);

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

            if (folderDetails.isOverFlow == true)
            {
                if (limitationsObj.folderList.Where(f => f.fold.FolderID == id).FirstOrDefault().itemCount <= limitationsObj.maxItemCountPerFolder)
                {
                    folderDetails.isOverFlow = false;
                    folderDetails = CCFolderRepository.SaveFolder(folderDetails);
                }
            }
            return RedirectToAction("Items", "Folder", new { ID = fid });
        }
        public ActionResult SelectFolderoptionss(SelectFolderViewModel model)
        {
            TempData["SelectedMenu"] = "Manage";
            TempData["SelectedSubMenu"] = "ManageFolders";
            Account accountObj = (Account)Session["account"];
            int type = 1;
            CCFolder folderDetails = null;
            folderDetails = CCFolderRepository.FolderDetails(model.PrimarySourceId);
            if (folderDetails != null) { type = folderDetails.Type; }
            else { type = 1; }

            User userObj = (User)Session["user"];

            var connection = new CorporateContacts.Domain.Entities.CCConnection();
            connection.FolderID = model.PrimarySourceId;
            connection.FolderName = model.SelectedFolderName;
            connection.Owner = model.SelectedFolderOwnerInfo;
            if (type == 1) { connection.Type = "Contact"; }
            else { connection.Type = "Calendar"; }
            connection.CredentialsID = model.CredentialID;
            connection.AllowAdditions = false;
            connection.IgnoreExisting = model.IgnoreExisting;
            connection.SyncDirection = model.SyncDirection;
            connection.CategoryFilterUsed = model.CategoryFilterUsed;
            connection.CopyPhotos = model.CopyPhotos;
            connection.TurnOffReminders = model.TurnOffReminders;
            connection.SourceID = model.SelectedFolderId;
            connection.Frequency = 1440;
            connection.IsRunning = false;
            connection.IsPaused = false;
            connection.SecondaryAccount = Session["secondaryAccount"] as string;
            string accessTypes = string.Empty;
            if (Session["accessType"] != null) { accessTypes = Session["accessType"].ToString(); }
            if (string.IsNullOrEmpty(accessTypes)) { connection.AccessType = 0; }
            else { connection.AccessType = Int32.Parse(accessTypes); }
            string format = "yyyy-MM-dd HH:mm";
            connection.LastSyncTime = ((DateTime)(System.Data.SqlTypes.SqlDateTime.MinValue)).ToString(format);
            if (model.CategoryFilterUsed == false) { connection.CategoryFilterValues = string.Empty; }
            else { connection.CategoryFilterValues = model.CategoryFilterValues; }
            if (model.TagAllSubject == true) { connection.SubjectTag = model.SubjectTag; }
            else { connection.SubjectTag = string.Empty; }
            connection.tagSubject = model.TagAllSubject;
            connection.AccountGUID = accountObj.AccountGUID;
            connection = CCConnectinRepository.SaveSubscription(connection);

            if (connection != null)
            {
                var foldertag = new CorporateContacts.Domain.Entities.CCConnection();
                var tagname = connection.FolderName + "[" + connection.ConnectionID + "]";
                foldertag.Tag = tagname;
                foldertag.ConnectionID = connection.ConnectionID;

                CCConnectinRepository.SaveSubscriptionTag(foldertag);
            }

            var res = CCFieldMappingsRepository.SaveAllMappingFields(connection.FolderID, connection.ConnectionID, accountObj.AccountGUID);

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

            return RedirectToAction("ViewConnections", "Folder", new { id = connection.FolderID });
        }
        public ActionResult ImportContacts(long id)
        {
            User userObj = (User)Session["user"];
            Account accountObj = (Account)Session["account"];

            var folderName = CCFolderRepository.CCFolders.FirstOrDefault(fid => fid.FolderID == id & fid.AccountGUID == accountObj.AccountGUID).Name;
            ViewBag.foldername = folderName;

            if (Request.Files.Count > 0)
            {
                var file = Request.Files[0];

                if (file != null && file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
                    string fileExtension = System.IO.Path.GetExtension(path);

                    if (fileExtension == ".xls" || fileExtension == ".xlsx")
                    {
                        ViewBag.MessageExtention = "";

                        file.SaveAs(path);

                        ItemsImporter importcontact = new ItemsImporter(CCFieldRepository, CCFieldValueRepository, CCItemRepository);

                        LimitationsViewModel limitationsObj = (LimitationsViewModel)Session["limitations"];

                        long maxItemImportCount = limitationsObj.maxItemCountPerFolder - limitationsObj.folderList.Where(f => f.fold.FolderID == id).FirstOrDefault().itemCount;

                        long numberOfContacts = importcontact.ImportInputContacts(id, accountObj.AccountGUID, path, fileExtension, maxItemImportCount);

                        if (System.IO.File.Exists(path))
                        {
                            System.IO.File.Delete(path);
                        }

                        if (numberOfContacts == -2)
                        {
                            ViewBag.MessageItemImportExceed = "The number of contacts to be imported exceeds the Max Item per Folder Count";
                            //ViewBag.Message = "";
                            //ViewBag.MessagePass = "";
                        }
                        else if (numberOfContacts > 0)
                        {
                            ViewBag.MessagePass = "******" + (numberOfContacts - 1) + " contacts were imported.";
                            //ViewBag.Message = "";
                            //ViewBag.MessageItemImportExceed = "";
                        }
                        else
                        {
                            ViewBag.Message = "No matching fields were found in the imported file. O contacts imported.";
                            //ViewBag.MessagePass = "";
                            //ViewBag.MessageItemImportExceed = "";
                        }

                    }

                    else
                    {
                        ViewBag.MessageExtention = "Please select the .xls or .xlsx file";
                        //ViewBag.MessagePass = "";
                        //ViewBag.MessageItemImportExceed = "";
                        //ViewBag.Message = "";
                    }

                }
            }

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

            return View(id);
            //  return RedirectToAction("ImportContacts");
        }
        public ActionResult ImportBulkConnections(ImportConnectionListModel model)
        {
            long fid = model.selectedFolderID;

            User userObj = (User)Session["user"];
            Account accountObj = (Account)Session["account"];
            long numberOfConnections = 0;

            var folderName = CCFolderRepository.CCFolders.FirstOrDefault(f => f.FolderID == fid & f.AccountGUID == accountObj.AccountGUID).Name;
            ViewBag.foldername = folderName;
            ConnectionImportListSummaryModel connSummary = new ConnectionImportListSummaryModel();

            if (Request.Files.Count > 0)
            {
                var file = Request.Files[0];

                if (file != null && file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
                    string fileExtension = System.IO.Path.GetExtension(path);

                    if (fileExtension == ".xls" || fileExtension == ".xlsx")
                    {
                        ViewBag.MessageExtention = "";

                        file.SaveAs(path);

                        LimitationsViewModel limitationsObj = (LimitationsViewModel)Session["limitations"];

                        long maxConnectionImportCount = limitationsObj.availableCconnectionCount;

                        ConnectionImporter importConnection = new ConnectionImporter(CCConnectinRepository, CCFolderRepository, CCCredentialRepository, CCFieldMappingsRepository);
                        connSummary = importConnection.ImportConnections(fid, accountObj.AccountGUID, path, fileExtension, model.SelectedCredentialID, model.SelectedImporsanationOrDelegation, model.SyncDirection, maxConnectionImportCount);

                        if (System.IO.File.Exists(path))
                        {
                            System.IO.File.Delete(path);
                        }

                        //if (numberOfConnections > 0)
                        //{
                        //    ViewBag.MessagePass = "******" + (numberOfConnections - 1) + " contacts were imported.";
                        //    ViewBag.Message = "";
                        //}
                        //else
                        //{
                        //    ViewBag.Message = "No matching fields were found in the imported file. O contacts imported.";
                        //    ViewBag.MessagePass = "";
                        //}
                    }
                    else
                    {
                        ViewBag.MessageExtention = "Please select the .xls or .xlsx file";
                    }
                }
            }

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

            Session["newConnections"] = connSummary;

            return RedirectToAction("ViewConnections", "Folder", new { id = fid });
        }
        public ActionResult AddContact(AddContactViewModel objContact)
        {
            Account accountObj = (Account)Session["account"];
            string timeZone = (string)Session["timeZone"];
            int type = 1;
            ItemsImporter importcontact = new ItemsImporter(CCFieldRepository, CCFieldValueRepository, CCItemRepository);
            CCFolder folderDetails = null;
            folderDetails = CCFolderRepository.FolderDetails(objContact.FolderID);
            if (folderDetails != null) { type = folderDetails.Type; }
            else { type = 1; }
            bool res = importcontact.ImportSingleContact(objContact, type, accountObj.AccountGUID, timeZone);

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

            if (res) return RedirectToAction("Items", "Folder", new { id = objContact.FolderID });
            else { return RedirectToAction("AddContact", "Folder", new { id = objContact.FolderID, state = 1 }); }
        }
        public int checkToFreezeAccount(Account acc)
        {
            var folderList = CCFolderRepository.CCFolders.Where(f => f.AccountGUID == acc.AccountGUID).ToList();

            foreach(var fold in folderList)
            {
                int FolderItemCount = CCItemRepository.CCContacts.Where(i => i.FolderID == fold.FolderID).Count();

                LimitationsViewModel limitationsObj = new LimitationsViewModel();
                HelperFunctions HF = new HelperFunctions();
                limitationsObj = HF.updateAccountLimitations(acc);

                if ((FolderItemCount > limitationsObj.maxItemCountPerFolder) | (fold.isOverFlow == true))
                {
                    return 1;
                }
            }
            return 0;
        }
예제 #10
0
        public ActionResult Index()
        {
            TempData["SelectedMenu"] = "Summary";
            TempData["SelectedSubMenu"] = "";
            TempData["SelectedSubMenuFolder"] = "";
            User userObj = (User)Session["user"];
            Account accountObj = (Account)Session["account"];
            if (userObj != null)
            {
                //if (accountObj.isOverFlow == true)
                //{
                //    return RedirectToAction("BillingOptions", "Admin", new { id = 1 });
                //}

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

                if (userObj.isPasswordChange == false)
                {
                    return RedirectToAction("ChangePassword", "Admin");
                }

                if (Session["trialData"] == null)
                {
                    if (accountObj.HasPurchased == false)
                    {
                        if ((((DateTime)(accountObj.TrialEnds) - (DateTime)(DateTime.Now.Date)).TotalDays > (CCGlobalValues.trialPeriod - 2)) | (((DateTime)(accountObj.TrialEnds) - (DateTime)(DateTime.Now.Date)).TotalDays < 2))
                        {
                            TrialDataModel trialObj = new TrialDataModel();
                            trialObj.hasPurchased = accountObj.HasPurchased;
                            trialObj.createdDate = accountObj.CreatedDate;
                            trialObj.trialEndDate = accountObj.TrialEnds;
                            trialObj.showPurchaseOptions = true;
                            Session["trialData"] = trialObj;

                            return RedirectToAction("Index", "Admin");
                        }
                        else if (((DateTime)(accountObj.TrialEnds) - (DateTime)(DateTime.Now.Date)).TotalDays < CCGlobalValues.trialPeriod)
                        {
                            TrialDataModel trialObj = new TrialDataModel();
                            trialObj.hasPurchased = accountObj.HasPurchased;
                            trialObj.createdDate = accountObj.CreatedDate;
                            trialObj.trialEndDate = accountObj.TrialEnds;
                            trialObj.showPurchaseOptions = true;
                            Session["trialData"] = trialObj;
                        }
                    }
                }

                if (accountObj.HasPurchased == true & Session["trialData"] != null)
                {
                    Session["trialData"] = null;
                }

                AdminViewModel ObjModel = new AdminViewModel();
                List<AdminDashboardViewModel> objDash = new List<AdminDashboardViewModel>();
                List<List<ConnectionInforViewModel>> connectionInforByConnction = new List<List<ConnectionInforViewModel>>();

                if (CCFolderRepository.CCFolders != null) { }
                var allFolders = CCFolderRepository.CCFolders.Where(guid => guid.AccountGUID == accountObj.AccountGUID).ToList();

                ObjModel.noOfFolders = CCFolderRepository.CCFolders.Where(F => F.AccountGUID == accountObj.AccountGUID).Count();
                ObjModel.noOfConnections = CCConnectionRepository.CCSubscriptions.Where(C => C.AccountGUID == accountObj.AccountGUID).Count();
                ObjModel.noOfUsers = CCUserRepository.Users.Where(U => U.AccountID == userObj.AccountID).Count();
                //ObjModel.noOfSubscriptionsPurchased = 0;
                ObjModel.noOfTotalItems = CCItemRepository.CCContacts.Where(I => I.AccountGUID == accountObj.AccountGUID & I.isDeleted == false).Count();

                // get saved quantity
                var accDetails = accountRepo.Accounts.Where(aguid => aguid.AccountGUID == accountObj.AccountGUID).FirstOrDefault();
                var planLeval = planRepository.Plans.Where(pid => pid.ID == accDetails.PlanID).FirstOrDefault().PlanLevel;

                    var featureQuality = featureRepository.Features.Where(pid => pid.PlanLevel == planLeval & pid.Type == "Max Items per Folder").FirstOrDefault();
                    var savedQuality = purchRepository.Purchases.Where(fid => fid.FeatureID == featureQuality.ID && fid.AccountGUID == accountObj.AccountGUID).FirstOrDefault();

                    if (savedQuality != null)
                    {
                        var quantitySaved = (savedQuality.Quantity) / (featureQuality.Quantity);
                        ObjModel.NoOfConnection = quantitySaved * 5;
                        ObjModel.noOfSubscriptionsPurchased = quantitySaved;
                        //limitationsObj.availableCconnectionCount = (int)ObjModel.NoOfConnection - (int)ObjModel.noOfConnections;
                        //limitationsObj.maxItemCountPerFolder = featureQuality.Quantity;
                        //if (featureRepository.Features.Where(pid => pid.PlanLevel == planLeval & pid.Type == "Sync Calendar").FirstOrDefault().Quantity == 0)
                        //    limitationsObj.isCalendarSyncAvailable = false;
                        //else
                        //    limitationsObj.isCalendarSyncAvailable = true;
                    }
                    else
                    {
                        ObjModel.NoOfConnection = 0;
                        ObjModel.noOfSubscriptionsPurchased = 0;
                    }

                foreach (var folder in allFolders)
                {
                    AdminDashboardViewModel dash = new AdminDashboardViewModel();
                    List<ConnectionInforViewModel> connectionInforByFolder = new List<ConnectionInforViewModel>();

                    dash.FolderName = folder.Name;
                    dash.FolderID = folder.FolderID;
                    dash.FolderType = folder.Type;
                    dash.NumberOfItems = CCContactRepository.CCContacts.Where(fid => fid.FolderID == folder.FolderID & fid.AccountGUID == accountObj.AccountGUID & fid.isDeleted == false).Count();
                    dash.NumberOfConnections = CCConnectionRepository.CCSubscriptions.Where(fid => fid.FolderID == folder.FolderID & fid.AccountGUID == accountObj.AccountGUID).Count();

                    if (folder.IsPaused == false)
                    {
                        dash.IsPaused = false;
                    }
                    else
                    {
                        dash.IsPaused = true;
                    }
                    objDash.Add(dash);

                    var connections = CCConnectionRepository.CCSubscriptions.Where(fid => fid.FolderID == folder.FolderID & fid.AccountGUID == accountObj.AccountGUID);
                    foreach (var conn in connections)
                    {
                        ConnectionInforViewModel connectionInfor = new ConnectionInforViewModel();
                        connectionInfor.FolderName = folder.Name;
                        connectionInfor.ConnctionFolderName = conn.FolderName;
                        connectionInfor.ConnectionID = conn.ConnectionID;

                        if (DateTime.Parse(conn.LastSyncTime) < DateTime.Parse("1902-01-01 00:00"))
                        {
                            connectionInfor.LastSyncTime = "Never";
                        }
                        else
                        {

                            DateTime timeUtc = DateTime.Parse(conn.LastSyncTime);
                            DateTime cstTime = new DateTime();
                            try
                            {
                                TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById(accountObj.TimeZone.ToString());
                                cstTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, cstZone);
                                Console.WriteLine("The date and time are {0} {1}.",
                                                  cstTime,
                                                  cstZone.IsDaylightSavingTime(cstTime) ?
                                                          cstZone.DaylightName : cstZone.StandardName);
                            }
                            catch (TimeZoneNotFoundException)
                            {
                                Console.WriteLine("Timezone conversion error");
                            }
                            catch (InvalidTimeZoneException)
                            {
                                Console.WriteLine("conn.LastSyncTime");
                            }

                            connectionInfor.LastSyncTime = cstTime.ToString();

                            //connectionInfor.LastSyncTime = conn.LastSyncTime;
                        }
                        connectionInfor.Type = conn.Type;
                        connectionInfor.FolderID = folder.FolderID;
                        if (conn.IsRunning == null) { connectionInfor.IsRunning = false; }
                        else if (conn.IsRunning == false) { connectionInfor.IsRunning = false; }
                        else if (conn.IsRunning == true) { connectionInfor.IsRunning = true; }
                        if (conn.IsPaused == false)
                        {
                            connectionInfor.IsPaused = false;
                            connectionInfor.rowClass = "notPaused ";
                        }
                        else
                        {
                            connectionInfor.IsPaused = true;
                            connectionInfor.rowClass = "Paused ";
                        }
                        connectionInforByFolder.Add(connectionInfor);

                    }

                    connectionInforByConnction.Add(connectionInforByFolder);

                }
                var assemblyVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
                ViewBag.version = assemblyVersion;
                Session["version"] = assemblyVersion;
                ObjModel.FoldersInfor = objDash;
                ObjModel.ConnectionsInfor = connectionInforByConnction;
                return View(ObjModel);
            }
            return View();
        }
예제 #11
0
        public ActionResult SaveFeatures(string plan, int quantities, string couponID)
        {
            User userObj = (User)Session["user"];
            Account accountObj = (Account)Session["account"];
            int planLevel = Int32.Parse(plan);
            int existingPlanID = accountObj.PlanID;
            string purchaseType = "Upgrade";

            ////Delete old purchasedfeature
            //var purchasedfeatures = purchRepository.Purchases.Where(p => p.AccountGUID == accountObj.AccountGUID).ToList();
            //foreach (var purch in purchasedfeatures)
            //{
            //    bool res = purchRepository.DeleteFPurchasedFeature(purch.ID);

            //}

            //var featuresForPlan = featureRepository.Features.Where(pl => pl.PlanLevel == planLevel).ToList();

            //// save default feature
            //var featuresForDefaultPlan = featureRepository.Features.Where(pl => pl.PlanLevel == planLevel && pl.Price == 0).ToList();

            //foreach (var feat in featuresForDefaultPlan)
            //{
            //    PurchasedFeatures objFeature = new PurchasedFeatures();
            //    objFeature.AccountGUID = accountObj.AccountGUID;
            //    objFeature.FeatureID = feat.ID;
            //    objFeature.ExpiryDate = DateTime.UtcNow;
            //    objFeature.Enabled = true;

            //    if (feat.Type == "Max Items per Folder")
            //    {
            //        objFeature.Quantity = (feat.Quantity) * quantities;
            //    }
            //    else
            //    {
            //        objFeature.Quantity = feat.Quantity;
            //    }

            //    purchRepository.SavePurchase(objFeature);
            //}

            ////Ajust Folder Fields START

            //List<string> needtosave = new List<string>();
            //List<CCFolderField> savedobj = new List<CCFolderField>();
            //List<CCFolderField> activeFields = new List<CCFolderField>();
            //List<CCFolderField> needToInActive = new List<CCFolderField>();

            //List<String> objFields = new List<string>();

            //if(planLevel == 10)
            //    objFields = FieldsConfigHelper.GetFieldForAppointmentSimple();
            //else if(planLevel == 20)
            //    objFields = FieldsConfigHelper.GetFieldForContactBusiness();
            //else
            //    objFields = FieldsConfigHelper.GetFieldForContactFull();

            //var folderListForAccount = CCFolderRepository.CCFolders.Where(F => F.AccountGUID == accountObj.AccountGUID).ToList();

            //foreach (var fold in folderListForAccount)
            //{
            //    needtosave = CCFieldRepository.IsAvailableField(objFields, fold.FolderID);

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

            //    foreach (var field in objFields)
            //    {
            //        CCFolderField folderField = CCFieldRepository.CCFolderFields.Where(f => f.FieldCaption == field & f.AccountGUID == accountObj.AccountGUID & f.FolderID == fold.FolderID).FirstOrDefault();
            //        activeFields.Add(folderField);
            //    }

            //    var resp = CCFieldRepository.SaveFolderFieldsObj(savedobj);

            //    var fieldList = CCFieldRepository.CCFolderFields.Where(f => f.AccountGUID == accountObj.AccountGUID & f.FolderID == fold.FolderID).ToList();

            //    var toInActiveList = fieldList.Except(activeFields).ToList();

            //    int flag = 0;

            //    foreach (var f1 in fieldList)
            //    {
            //        flag = 0;
            //        foreach (var f2 in activeFields)
            //        {
            //            try
            //            {
            //                if (f2.FieldID == f1.FieldID)
            //                {
            //                    if (f1.isActive != false)
            //                    {
            //                        flag = 1;
            //                        break;
            //                    }
            //                    else
            //                    {
            //                        flag = 2;
            //                        break;
            //                    }

            //                }
            //            }
            //            catch (Exception ex)
            //            { }

            //        }

            //        if (flag == 0)
            //        {
            //            f1.isActive = false;
            //            CCFieldRepository.SaveFolderFields(f1);
            //        }

            //        else if (flag == 2)
            //        {
            //            f1.isActive = true;
            //            CCFieldRepository.SaveFolderFields(f1);
            //        }
            //    }

            //    // add field into default group
            //    var defaultGrp = CCGroupRepository.CCGroups.Where(fid => fid.FolderID == fold.FolderID & fid.GroupName == "Default" & fid.AccountGUID == accountObj.AccountGUID).FirstOrDefault();

            //    if (defaultGrp != null)
            //    {
            //        foreach (var field in resp)
            //        {
            //            long grpFieldOrder = 0;
            //            // get group fileds last order
            //            var groupFieldOrder = CCGroupFieldRepository.CCGroupsFields.Where(gid => gid.GroupID == defaultGrp.GroupID & gid.AccountGUID == accountObj.AccountGUID).OrderByDescending(grp => grp.FieldOrder).FirstOrDefault();
            //            if (groupFieldOrder != null) { grpFieldOrder = groupFieldOrder.FieldOrder; }

            //            CCGroupField objgrpfield = new CCGroupField();
            //            objgrpfield.FieldID = field.FieldID;
            //            objgrpfield.FieldOrder = grpFieldOrder + 1;
            //            objgrpfield.FolderID = defaultGrp.FolderID;
            //            objgrpfield.GroupID = defaultGrp.GroupID;
            //            objgrpfield.AccountGUID = accountObj.AccountGUID;
            //            var aa = CCGroupFieldRepository.SaveGroupField(objgrpfield);
            //        }
            //    }
            //}

            ////Ajust Folder Fields END

            //// change the plain id
            var planid = planRepository.Plans.FirstOrDefault(pl => pl.PlanLevel == planLevel).ID;

            var currentAccount = accountRepo.Accounts.FirstOrDefault(ac => ac.ID == userObj.AccountID);

            //Account account = new Account();
            //account = currentAccount;
            //existingPlanID = account.PlanID;
            //account.PlanID = planid;

            var account = saveFeaturesCommon(plan, quantities);

            account.HasPurchased = true;

            if (currentAccount.TrialEnds <= DateTime.Now.Date & currentAccount.HasPurchased == false & currentAccount.isOverFlow == true)
            {
                account.isOverFlow = false;
            }

            Session["trialData"] = null;

            if (existingPlanID > planid)
            {
                purchaseType = "Downgrade";
            }

            if (accountObj.isPaymentIssue == true)
            {
                account.isPaymentIssue = false;
            }

            account = accountRepo.SaveAccount(account);

            LimitationsViewModel limitationsObj = (LimitationsViewModel)Session["limitations"];
            HelperFunctions HF = new HelperFunctions();
            limitationsObj = HF.updateAccountLimitations(account);
            Session["limitations"] = limitationsObj;

            HF.CheckAcccountStatus(account);

            //Reset Sync Times
            var ConnectionList = CCConnectionRepository.CCSubscriptions.Where(con => con.AccountGUID == account.AccountGUID).ToList();

            foreach (var con in ConnectionList)
            {
                con.ResetAtNextSync = true;
                CCConnectionRepository.SaveSubscription(con);
            }

            var folderDetails = CCFolderRepository.CCFolders.Where(f => f.AccountGUID == account.AccountGUID).ToList();

            foreach (var fold in folderDetails)
            {
                if (fold.isOverFlow == true)
                {
                    if (limitationsObj.folderList.Where(f => f.fold.FolderID == fold.FolderID).FirstOrDefault().itemCount <= limitationsObj.maxItemCountPerFolder)
                    {
                        fold.isOverFlow = false;
                        CCFolderRepository.SaveFolder(fold);
                    }
                }
            }

            Session["account"] = account;

            //var featureQuality = featureRepository.Features.Where(pid => pid.PlanLevel == planLevel & pid.Type == "Max Items per Folder").FirstOrDefault();
            //var savedQuality = purchRepository.Purchases.Where(fid => fid.FeatureID == featureQuality.ID && fid.AccountGUID == accountObj.AccountGUID).FirstOrDefault();

            //if (savedQuality != null)
            //{
            //    var quantitySaved = (savedQuality.Quantity) / (featureQuality.Quantity);
            //    limitationsObj.availableCconnectionCount = (int)(quantitySaved * 5) - (int)CCConnectionRepository.CCSubscriptions.Where(C => C.AccountGUID == accountObj.AccountGUID).Count();
            //    limitationsObj.maxItemCountPerFolder = featureQuality.Quantity;
            //    if (featureRepository.Features.Where(pid => pid.PlanLevel == planLevel & pid.Type == "Sync Calendar").FirstOrDefault().Quantity == 0)
            //        limitationsObj.isCalendarSyncAvailable = false;
            //    else
            //        limitationsObj.isCalendarSyncAvailable = true;
            //}

            List<NotificationListViewModel> notificationList = new List<NotificationListViewModel>();
            notificationList = HF.generateNotificationList(account);
            if (notificationList.Count > 0)
                Session["notifications"] = notificationList;
            else
                Session["notifications"] = null;

            var currentAccountDetails = accountRepo.Accounts.FirstOrDefault(aid => aid.ID == userObj.AccountID);

            if (currentAccountDetails.StripeCustomerID != null)
            {
                ChargeFromExistingDetails(existingPlanID, quantities, couponID);
            }

            if (account != null)
            {
                if (currentAccountDetails.StripeCustomerID == null)
                {
                    return Json("SucessNew", JsonRequestBehavior.AllowGet);
                }
                else
                {
                    return Json("Sucess", JsonRequestBehavior.AllowGet);
                }

            }
            else
            {
                return Json("Fail", JsonRequestBehavior.AllowGet);
            }
        }