Example #1
0
        public long update(StrataBoardModel objectModel)
        {
            long count          = -2;
            long stratasBoardId = 0;
            long userClientId   = 0;

            if (objectModel.StratasBoardId > 0)
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        // Table StratasBoard
                        tblStratasBoard tblStratasBoardDb = new tblStratasBoard();
                        tblStratasBoardDb.StratasBoardId   = objectModel.StratasBoardId;
                        tblStratasBoardDb.StratasBoardName = objectModel.StratasBoardName;
                        tblStratasBoardDb.BuildingName     = objectModel.BuildingName;
                        tblStratasBoardDb.PortalLink       = objectModel.PortalLink.Trim();
                        tblStratasBoardDb.Status           = objectModel.Status;
                        tblStratasBoardDb.ModifiedBy       = AdminSessionData.AdminUserId;
                        tblStratasBoardDb.ModifiedOn       = DateTime.UtcNow;
                        tblStratasBoardDb.ModifiedFromIP   = HttpContext.Current.Request.UserHostAddress;
                        if (objectModel.PortalLink == objectModel.RequestPortalLink)
                        {
                            tblStratasBoardDb.RequestCounter = 1;
                        }

                        context.tblStratasBoards.Attach(tblStratasBoardDb);
                        context.Entry(tblStratasBoardDb).Property(x => x.StratasBoardName).IsModified = true;
                        context.Entry(tblStratasBoardDb).Property(x => x.BuildingName).IsModified     = true;
                        context.Entry(tblStratasBoardDb).Property(x => x.PortalLink).IsModified       = true;
                        context.Entry(tblStratasBoardDb).Property(x => x.Status).IsModified           = true;
                        context.Entry(tblStratasBoardDb).Property(x => x.ModifiedBy).IsModified       = true;
                        context.Entry(tblStratasBoardDb).Property(x => x.ModifiedOn).IsModified       = true;
                        context.Entry(tblStratasBoardDb).Property(x => x.ModifiedFromIP).IsModified   = true;
                        context.Entry(tblStratasBoardDb).Property(x => x.RequestCounter).IsModified   = true;

                        // Table UserClient
                        count = context.SaveChanges();
                        if (count >= 0)
                        {
                            tblUserClient tblUserClientDb = new tblUserClient();
                            tblUserClientDb.UserClientId   = objectModel.UserClientId;
                            tblUserClientDb.FirstName      = objectModel.FirstName;
                            tblUserClientDb.LastName       = objectModel.LastName;
                            tblUserClientDb.EmailId        = objectModel.EmailId;
                            tblUserClientDb.ContactNumber  = objectModel.ContactNumber;
                            tblUserClientDb.ModifiedBy     = AdminSessionData.AdminUserId;
                            tblUserClientDb.ModifiedOn     = DateTime.UtcNow;
                            tblUserClientDb.ModifiedFromIP = HttpContext.Current.Request.UserHostAddress;

                            context.tblUserClients.Attach(tblUserClientDb);
                            context.Entry(tblUserClientDb).Property(x => x.FirstName).IsModified = true;
                            context.Entry(tblUserClientDb).Property(x => x.LastName).IsModified  = true;
                            //context.Entry(tblUserClientDb).Property(x => x.EmailId).IsModified = true;
                            context.Entry(tblUserClientDb).Property(x => x.ContactNumber).IsModified  = true;
                            context.Entry(tblUserClientDb).Property(x => x.ModifiedBy).IsModified     = true;
                            context.Entry(tblUserClientDb).Property(x => x.ModifiedOn).IsModified     = true;
                            context.Entry(tblUserClientDb).Property(x => x.ModifiedFromIP).IsModified = true;
                            count = context.SaveChanges();
                            if (count >= 0)
                            {
                                transaction.Commit();
                                count = objectModel.StratasBoardId;
                            }
                            else
                            {
                                transaction.Rollback();
                                count = -2;   // any error is there
                            }
                        }
                        else
                        {
                            transaction.Rollback();
                            count = -2;   // any error is there
                        }
                    }
                    catch (Exception ex)
                    {
                        new AppError().LogMe(ex);
                        transaction.Rollback();
                        count = -2;   // any error is there
                    }
                }
            }
            else
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    var subscriptionDetails = context.tblSubscriptions.Where(x => x.SubscriptionId == objectModel.SubscriptionId).FirstOrDefault();
                    try
                    {
                        // Table StratasBoard
                        tblStratasBoard tblStratasBoardDb = new tblStratasBoard();
                        tblStratasBoardDb.StratasBoardName = objectModel.StratasBoardName;
                        tblStratasBoardDb.BuildingName     = objectModel.BuildingName;
                        tblStratasBoardDb.PortalLink       = objectModel.PortalLink;
                        tblStratasBoardDb.CreatedBy        = AdminSessionData.AdminUserId;
                        tblStratasBoardDb.CreatedOn        = DateTime.UtcNow;
                        tblStratasBoardDb.CreatedFromIP    = HttpContext.Current.Request.UserHostAddress;
                        tblStratasBoardDb.Status           = objectModel.Status;
                        context.tblStratasBoards.Add(tblStratasBoardDb);
                        context.SaveChanges();
                        stratasBoardId = tblStratasBoardDb.StratasBoardId;
                        if (stratasBoardId > 0)
                        {
                            // Table UserClient
                            tblUserClient tblUserClientDb = new tblUserClient();
                            tblUserClientDb.FirstName           = objectModel.FirstName;
                            tblUserClientDb.LastName            = objectModel.LastName;
                            tblUserClientDb.EmailId             = objectModel.EmailId;
                            tblUserClientDb.Password            = AppLogic.EncryptPassword();
                            tblUserClientDb.ContactNumber       = objectModel.ContactNumber;
                            tblUserClientDb.StratasBoardId      = stratasBoardId;
                            tblUserClientDb.RoleName            = "A"; // StratasBoard Admin
                            tblUserClientDb.IsEmailNotification = true;
                            tblUserClientDb.IsSMSNotification   = true;
                            tblUserClientDb.IsProfileComplete   = false;
                            tblUserClientDb.Status        = 1; // It will be active in both the cases
                            tblUserClientDb.CreatedBy     = AdminSessionData.AdminUserId;
                            tblUserClientDb.CreatedOn     = DateTime.UtcNow;
                            tblUserClientDb.LastLogin     = DateTime.UtcNow;
                            tblUserClientDb.CurrentLogin  = DateTime.UtcNow;
                            tblUserClientDb.CreatedFromIP = HttpContext.Current.Request.UserHostAddress;
                            context.tblUserClients.Add(tblUserClientDb);
                            context.SaveChanges();
                            userClientId = tblUserClientDb.UserClientId;
                            if (userClientId > 0)
                            {
                                // Table StratasBoard Subscription
                                tblStratasBoardSubscription tblStratasBoardSubscriptionDb = new tblStratasBoardSubscription();
                                tblStratasBoardSubscriptionDb.StratasBoardId   = stratasBoardId;
                                tblStratasBoardSubscriptionDb.SubscriptionId   = objectModel.SubscriptionId;
                                tblStratasBoardSubscriptionDb.Validity         = subscriptionDetails.Validity;
                                tblStratasBoardSubscriptionDb.IsSmsForAlert    = subscriptionDetails.IsSmsForAlert;
                                tblStratasBoardSubscriptionDb.IsSmsForReminder = subscriptionDetails.IsSmsForReminder;
                                tblStratasBoardSubscriptionDb.AllowedUser      = subscriptionDetails.AllowedUser;
                                tblStratasBoardSubscriptionDb.ExpiryDate       = AppLogic.CalculateSubscriptionExpiryDate(DateTime.UtcNow, subscriptionDetails.Validity);
                                tblStratasBoardSubscriptionDb.CreatedBy        = AdminSessionData.AdminUserId;
                                tblStratasBoardSubscriptionDb.CreatedOn        = DateTime.UtcNow;
                                tblStratasBoardSubscriptionDb.Status           = 1;
                                context.tblStratasBoardSubscriptions.Add(tblStratasBoardSubscriptionDb);
                                context.SaveChanges();
                                int stratasBoardSubscriptionId = tblStratasBoardSubscriptionDb.StratasBoardSubscriptionId;
                                if (stratasBoardSubscriptionId > 0)
                                {
                                    transaction.Commit();
                                    count = stratasBoardId;
                                }
                                else
                                {
                                    transaction.Rollback();
                                    count = -2;   // any error is there
                                }
                            }
                            else
                            {
                                transaction.Rollback();
                                count = -2;   // any error is there
                            }
                        }
                        else
                        {
                            transaction.Rollback();
                            count = -2;   // any error is there
                        }
                    }
                    catch (Exception ex)
                    {
                        new AppError().LogMe(ex);
                        transaction.Rollback();
                        count = -2;   // any error is there
                    }
                }
            }
            return(count);
        }
Example #2
0
        public int AddUpdateSubAdmin(SubAdminModel subAdminModel)
        {
            int result       = 0;
            int userClientId = 0;

            //using (var transaction = _context.Database.BeginTransaction())
            //{
            try
            {
                tblUserClient tblUserClientDb = new tblUserClient();
                tblUserClientDb.FirstName      = subAdminModel.FirstName;
                tblUserClientDb.LastName       = subAdminModel.LastName;
                tblUserClientDb.EmailId        = subAdminModel.Email;
                tblUserClientDb.Position       = subAdminModel.Position;
                tblUserClientDb.StratasBoardId = ClientSessionData.ClientStrataBoardId;
                tblUserClientDb.RoleName       = "SA";
                tblUserClientDb.CreatedBy      = ClientSessionData.UserClientId;
                tblUserClientDb.CreatedOn      = DateTime.UtcNow;
                tblUserClientDb.LastLogin      = DateTime.UtcNow;
                tblUserClientDb.CurrentLogin   = DateTime.UtcNow;
                if (subAdminModel.UserClientId == 0)
                {
                    tblUserClientDb.Password = AppLogic.EncryptPassword();
                    // tblUserClientDb.ContactNumber = subAdminModel.ContactNumber;
                    tblUserClientDb.IsEmailNotification = false;
                    tblUserClientDb.IsSMSNotification   = false;
                    tblUserClientDb.IsProfileComplete   = false;
                    tblUserClientDb.Status = 1;  // It will be active in both the cases
                    var AllowedUser = _context.tblStratasBoardSubscriptions.Where(x => x.StratasBoardId == ClientSessionData.ClientStrataBoardId).FirstOrDefault().AllowedUser;

                    var AddedUserClients = _context.tblUserClients.Where(x => x.StratasBoardId == ClientSessionData.ClientStrataBoardId && x.Status == 1);
                    if (AddedUserClients.Count() <= AllowedUser)
                    {
                        _context.tblUserClients.Add(tblUserClientDb);
                        _context.SaveChanges();
                    }
                    else
                    {
                        result = -3;
                    }
                }
                else
                {
                    tblUserClientDb.UserClientId = subAdminModel.UserClientId;
                    _context.tblUserClients.Attach(tblUserClientDb);
                    _context.Entry(tblUserClientDb).Property(x => x.FirstName).IsModified = true;
                    _context.Entry(tblUserClientDb).Property(x => x.LastName).IsModified  = true;
                    _context.Entry(tblUserClientDb).Property(x => x.EmailId).IsModified   = true;
                    _context.Entry(tblUserClientDb).Property(x => x.Position).IsModified  = true;
                    result = _context.SaveChanges();
                    if (result == 1)
                    {
                        result = 0;
                    }
                }
                userClientId = Convert.ToInt32(tblUserClientDb.UserClientId);
                if (userClientId > 0)
                {
                    if (!string.IsNullOrEmpty(subAdminModel.SelectedUserClientPrivilege))
                    {
                        if (subAdminModel.SelectedUserClientPrivilege != subAdminModel.PageIds)
                        {
                            int[] selectedPrivilegeArray = subAdminModel.SelectedUserClientPrivilege.Split(",".ToCharArray()).Select(x => int.Parse(x.ToString())).ToArray();
                            _context.tblUserPrivs.RemoveRange(_context.tblUserPrivs.Where(x => x.UserClientId == userClientId));
                            foreach (var item in selectedPrivilegeArray)
                            {
                                tblUserPriv tblUserPrivDb = new tblUserPriv();
                                tblUserPrivDb.PageId       = item;
                                tblUserPrivDb.UserClientId = userClientId;
                                tblUserPrivDb.Status       = 1;
                                tblUserPrivDb.CreatedBy    = ClientSessionData.UserClientId;
                                tblUserPrivDb.CreatedOn    = DateTime.UtcNow;
                                tblUserPrivDb.ModifiedBy   = ClientSessionData.UserClientId;
                                tblUserPrivDb.ModifiedOn   = DateTime.UtcNow;
                                _context.tblUserPrivs.Add(tblUserPrivDb);
                                result = _context.SaveChanges();
                            }
                            if (result == 1)
                            {
                                EmailSender.FncSend_StratasBoard_RegistrationMail_ToSubAdminClient(userClientId);
                            }
                        }
                    }
                    result = 0;
                }
            }
            catch (Exception ex)
            {
                new AppError().LogMe(ex);
                result = -2;   // any error is there
            }
            return(result);
        }
        public int AddUpdateStrataOwner(StrataOwnerModel strataOwnerModel)
        {
            int result       = 0;
            int userClientId = 0;

            //using (var transaction = _context.Database.BeginTransaction())
            //{
            try
            {
                tblUserClient tblUserClientDb = new tblUserClient();
                tblUserClientDb.FirstName      = strataOwnerModel.FirstName;
                tblUserClientDb.LastName       = strataOwnerModel.LastName;
                tblUserClientDb.EmailId        = strataOwnerModel.Email;
                tblUserClientDb.StratasBoardId = ClientSessionData.ClientStrataBoardId;
                tblUserClientDb.RoleName       = "O";
                tblUserClientDb.UnitNumber     = strataOwnerModel.UnitNumber;
                tblUserClientDb.CreatedBy      = ClientSessionData.UserClientId;
                tblUserClientDb.CreatedOn      = DateTime.UtcNow;
                tblUserClientDb.LastLogin      = DateTime.UtcNow;
                tblUserClientDb.CurrentLogin   = DateTime.UtcNow;
                if (strataOwnerModel.UserClientId == 0)
                {
                    tblUserClientDb.Password            = AppLogic.EncryptPassword();;
                    tblUserClientDb.IsEmailNotification = false;
                    tblUserClientDb.IsSMSNotification   = false;
                    tblUserClientDb.IsProfileComplete   = false;
                    tblUserClientDb.Status = 1;  // It will be active in both the cases
                    var AllowedUser = _context.tblStratasBoardSubscriptions.Where(x => x.StratasBoardId == ClientSessionData.ClientStrataBoardId).FirstOrDefault().AllowedUser;

                    var AddedUserClients = _context.tblUserClients.Where(x => x.StratasBoardId == ClientSessionData.ClientStrataBoardId && x.Status == 1);
                    if (AddedUserClients.Count() <= AllowedUser)
                    {
                        _context.tblUserClients.Add(tblUserClientDb);
                        result = _context.SaveChanges();
                    }
                    else
                    {
                        result = -3;
                    }
                    userClientId = Convert.ToInt32(tblUserClientDb.UserClientId);
                    if (result == 1)
                    {
                        EmailSender.FncSend_StratasBoard_RegistrationMail_ToStrataOwnerClient(userClientId);
                        result = 0;
                    }
                }
                else
                {
                    tblUserClientDb.UserClientId = strataOwnerModel.UserClientId;
                    _context.tblUserClients.Attach(tblUserClientDb);
                    _context.Entry(tblUserClientDb).Property(x => x.FirstName).IsModified  = true;
                    _context.Entry(tblUserClientDb).Property(x => x.LastName).IsModified   = true;
                    _context.Entry(tblUserClientDb).Property(x => x.EmailId).IsModified    = true;
                    _context.Entry(tblUserClientDb).Property(x => x.UnitNumber).IsModified = true;
                    result = _context.SaveChanges();
                    if (result == 1)
                    {
                        result = 0;
                    }
                }
            }
            catch (Exception ex)
            {
                new AppError().LogMe(ex);
                result = -2;   // any error is there
            }
            return(result);
        }