Ejemplo n.º 1
0
        public int Delete(StrataBoardModel objectModel)
        {
            int count = -1;

            // check the user exists on this strata, if exists then return...
            if (context.tblUserClients.Any(o => o.StratasBoardId == objectModel.StratasBoardId && o.RoleName.ToLower() != "a"))
            {
                count = -2;
                return(count);
            }

            // Delete the users on this strata
            if (context.tblUserClients.Any(x => x.StratasBoardId == objectModel.StratasBoardId))
            {
                context.tblUserClients.RemoveRange(context.tblUserClients.Where(x => x.StratasBoardId == objectModel.StratasBoardId));
                context.SaveChanges();
                count = 0;
            }

            // Delete the subscription details on this strata
            if (context.tblStratasBoardSubscriptions.Any(x => x.StratasBoardId == objectModel.StratasBoardId))
            {
                context.tblStratasBoardSubscriptions.RemoveRange(context.tblStratasBoardSubscriptions.Where(x => x.StratasBoardId == objectModel.StratasBoardId));
                context.SaveChanges();
                count = 0;
            }


            tblStratasBoard tblStratasBoardDb = new tblStratasBoard();

            tblStratasBoardDb.StratasBoardId       = objectModel.StratasBoardId;
            context.Entry(tblStratasBoardDb).State = EntityState.Deleted;
            count = context.SaveChanges();
            if (count == 1)
            {
                count = 0;
            }
            else
            {
                count = -1;
            }
            return(count);
        }
Ejemplo n.º 2
0
        public int ActDeact(StrataBoardModel objectModel)
        {
            tblStratasBoard tblStratasBoardDb = new tblStratasBoard();

            tblStratasBoardDb.StratasBoardId = objectModel.StratasBoardId;
            tblStratasBoardDb.Status         = objectModel.Status;

            context.tblStratasBoards.Attach(tblStratasBoardDb);
            context.Entry(tblStratasBoardDb).Property(x => x.Status).IsModified = true;

            int count = context.SaveChanges();

            if (count == 1)
            {
                count = 0;
            }
            else
            {
                count = -1;
            }

            return(count);
        }
Ejemplo n.º 3
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);
        }