Example #1
0
 public void DeleteOrganization(SMSA_Organization_ST org)
 {
     try
     {
         db.Entry(org).State = EntityState.Deleted;
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
         //return 0;
     }
 }
Example #2
0
 public void UpdateOrganization(SMSA_Organization_ST org)
 {
     try
     {
         db.Configuration.ProxyCreationEnabled = false;
         db.Entry(org).State = EntityState.Modified;
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
         //return 0;
     }
 }
 public void DeleteOrganization(SMSA_Organization_ST org)
 {
     try
     {
         dbUser.Timeout     = System.Threading.Timeout.Infinite;
         org.OrgIDSpecified = true;
         dbUser.DeleteOrganization(org);
         dbUser.Dispose();
         dbUser.Abort();
     }
     catch (Exception ex)
     {
         dbUser.Dispose();
         dbUser.Abort();
         throw ex;
     }
 }
 public int InsertOrganization(SMSA_Organization_ST org)
 {
     try
     {
         dbUser.Timeout = System.Threading.Timeout.Infinite;
         int  UserTypeId = 0;
         bool specified  = true;
         dbUser.InsertOrganization(org, out UserTypeId, out specified);
         dbUser.Dispose();
         dbUser.Abort();
         return(UserTypeId);
     }
     catch (Exception ex)
     {
         dbUser.Dispose();
         dbUser.Abort();
         throw ex;
     }
 }
Example #5
0
        public int InsertOrganization(SMSA_Organization_ST org)
        {
            try
            {
                db.Configuration.ProxyCreationEnabled = false;
                int maxOrgId = 0;
                if (db.SMSA_Organization_ST.Count() > 0)
                {
                    maxOrgId = db.SMSA_Organization_ST.Select(x => x.OrgID).Max();
                }
                maxOrgId  = maxOrgId + 1;
                org.OrgID = maxOrgId;
                db.SMSA_Organization_ST.Add(org);
                db.SaveChanges();

                return(maxOrgId);
            }
            catch (Exception ex)
            {
                throw ex;
                //return 0;
            }
        }
        public ActionResult Company(int?user, int?OrgId, int?CompanyId, CompanyDetail tt)
        {
            try
            {
                if (tt.CompanyID > 0)
                {
                    SMSA_CompanyMst_ST Comp = dbUser.GetCompanyById(tt.CompanyID);

                    #region Organization for each company
                    if (tt.POrgId.HasValue && tt.POrgId > 0)
                    {
                        #region Organization
                        SMSA_Organization_ST reqCompOrg = dbUser.GetOrganizationById(tt.OrgID);
                        reqCompOrg.OrgType            = tt.OrgType;
                        reqCompOrg.SaleAccId          = tt.SaleAccId;
                        reqCompOrg.SaleAccIdSpecified = true;
                        reqCompOrg.Description        = reqCompOrg.UserName == "Org" + Comp.UserName ? tt.CompanyName : reqCompOrg.Description;
                        dbUser.UpdateOrganization(reqCompOrg);
                        Comp.OrgID          = tt.POrgId.Value;
                        Comp.OrgIDSpecified = true;
                        #endregion
                    }
                    else
                    {
                        var lstOrg        = dbUser.GetAllOrganization();
                        var reqOrgDefault = lstOrg.Where(x => x.UserName == "Org" + tt.UserName).FirstOrDefault();
                        if (reqOrgDefault != null)
                        {
                            #region Organization
                            SMSA_Organization_ST reqCompOrg = dbUser.GetOrganizationById(reqOrgDefault.OrgID);
                            reqCompOrg.OrgType            = tt.OrgType;
                            reqCompOrg.SaleAccId          = tt.SaleAccId;
                            reqCompOrg.SaleAccIdSpecified = true;
                            reqCompOrg.Description        = reqCompOrg.UserName == "Org" + Comp.UserName ? tt.CompanyName : reqCompOrg.Description;
                            dbUser.UpdateOrganization(reqCompOrg);
                            Comp.OrgID          = reqOrgDefault.OrgID;
                            Comp.OrgIDSpecified = true;
                            #endregion
                        }
                        else
                        {
                            SMSA_Organization_ST org = new WPSService.SMSA_Organization_ST();
                            org.OrgType            = tt.OrgType;
                            org.SaleAccId          = tt.SubAgentId > 0 ? tt.SubAgentId : tt.AgentId > 0 ? tt.AgentId : org.SaleAccId;
                            org.SaleAccIdSpecified = true;
                            org.Status             = "A";
                            org.UserName           = "******" + tt.UserName;
                            org.CreatedBy          = user;
                            org.CreatedBySpecified = true;
                            org.CreatedOn          = DateTime.Now;
                            org.CreatedOnSpecified = true;
                            org.Description        = tt.CompanyName;
                            tt.POrgId           = dbUser.InsertOrganization(org);
                            Comp.OrgID          = tt.POrgId.Value;
                            Comp.OrgIDSpecified = true;
                            if (Membership.GetUser(org.UserName) == null)
                            {
                                MembershipCreateStatus status;
                                // Generate a new 12-character password with 1 non-alphanumeric character.
                                //y0t(9ci&xUn^
                                string password = org.UserName + "123"; // utility.GetUniqueKey(8);//Membership.GeneratePassword(8, 0);
                                                                        // string password = "******";

                                MembershipUser newUser = Membership.CreateUser(org.UserName, password, org.UserName, "ok", "ok", true, out status);
                                UserServiceClass.SMIM_UserMst_ST User = new UserServiceClass.SMIM_UserMst_ST();
                                User.UserId    = 0; User.UserName = org.UserName; User.Email = tt.Email;
                                User.FirstName = tt.ContactPerson; User.OrgId = tt.POrgId.Value;

                                utility.IsSpecifed <UserServiceClass.SMIM_UserMst_ST>(User);
                                int maxValue = db.InsertUser(User);
                            }
                        }
                    }
                    #endregion

                    #region Company


                    Comp.SMSA_Organization_ST = null;

                    Comp.Address            = tt.Address;
                    Comp.CompanyName        = tt.CompanyName;
                    Comp.ContactPerson      = tt.ContactPerson;
                    Comp.Email              = tt.Email;
                    Comp.EstID              = tt.EstID;
                    Comp.IsActive           = "Y";
                    Comp.IsApproved         = "Y";
                    Comp.logoPath           = tt.logoPath;
                    Comp.Mobile             = tt.Mobile;
                    Comp.Phone              = tt.Phone;
                    Comp.SaleAccIdSpecified = true;
                    if (tt.SubAgentId > 0)
                    {
                        Comp.SaleAccId = tt.SubAgentId;
                    }
                    else if (tt.AgentId > 0)
                    {
                        Comp.SaleAccId = tt.AgentId;
                    }
                    else
                    {
                        Comp.SaleAccId = null;
                    }

                    Comp.ModifyBy          = user;
                    Comp.ModifyBySpecified = true;
                    Comp.ModifyOn          = DateTime.Now;
                    Comp.ModifyOnSpecified = true;
                    dbUser.UpdateCompany(Comp);
                    #endregion

                    #region Activity Log
                    SMSA_Logs_HI log = new SMSA_Logs_HI();
                    utility.IsSpecifed <SMSA_Logs_HI>(log);
                    log.ActivityBy   = user.Value;
                    log.ActivityDesc = "Edit Company Details";
                    log.ActivityOn   = DateTime.Now;
                    log.ActivityType = "U";
                    log.ColumnId     = tt.CompanyID;
                    dbUser.AddActivityLog(log);
                    #endregion
                    //#region Organization
                    //SMSA_Organization_ST reqOrg = dbUser.GetOrganizationById(tt.OrgID);
                    //reqOrg.OrgType = tt.OrgType;
                    //reqOrg.SaleAccId = tt.SaleAccId;
                    //reqOrg.SaleAccIdSpecified = true;
                    //reqOrg.Description = reqOrg.UserName == "Org" + Comp.UserName ? tt.CompanyName : reqOrg.Description;
                    //dbUser.UpdateOrganization(reqOrg);
                    //#endregion

                    return(Json(new { success = true, response = "Company updated successfully." }));
                }
                else
                {
                    #region Organization for each company
                    if (tt.POrgId.HasValue && tt.POrgId > 0)
                    {
                        /*Organization laready defined and this company is part of group of companies*/
                    }
                    else
                    {
                        SMSA_Organization_ST org = new WPSService.SMSA_Organization_ST();
                        org.OrgType            = tt.OrgType;
                        org.SaleAccId          = tt.SubAgentId > 0 ? tt.SubAgentId : tt.AgentId > 0 ? tt.AgentId : org.SaleAccId;
                        org.SaleAccIdSpecified = true;
                        org.Status             = "A";
                        org.UserName           = "******" + tt.UserName;
                        org.CreatedBy          = user;
                        org.CreatedBySpecified = true;
                        org.CreatedOn          = DateTime.Now;
                        org.CreatedOnSpecified = true;
                        org.Description        = tt.CompanyName;
                        tt.POrgId = dbUser.InsertOrganization(org);

                        if (Membership.GetUser(org.UserName) == null)
                        {
                            MembershipCreateStatus status;
                            // Generate a new 12-character password with 1 non-alphanumeric character.
                            //y0t(9ci&xUn^
                            string password = org.UserName + "123"; //utility.GetUniqueKey(8);//Membership.GeneratePassword(8, 0);
                                                                    // string password = "******";

                            MembershipUser newUser = Membership.CreateUser(org.UserName, password, org.UserName, "ok", "ok", true, out status);
                            UserServiceClass.SMIM_UserMst_ST User = new UserServiceClass.SMIM_UserMst_ST();
                            User.UserId    = 0; User.UserName = org.UserName; User.Email = tt.Email;
                            User.FirstName = tt.ContactPerson; User.OrgId = tt.POrgId.Value;

                            utility.IsSpecifed <UserServiceClass.SMIM_UserMst_ST>(User);
                            int maxValue = db.InsertUser(User);
                        }
                    }
                    #endregion

                    #region Company Insertion

                    SMSA_CompanyMst_ST Comp = new SMSA_CompanyMst_ST();
                    Comp.OrgID              = tt.POrgId.Value;
                    Comp.OrgIDSpecified     = true;
                    Comp.Address            = tt.Address;
                    Comp.CompanyName        = tt.CompanyName;
                    Comp.ContactPerson      = tt.ContactPerson;
                    Comp.CreatedBy          = user;
                    Comp.CreatedBySpecified = true;
                    Comp.CreatedOn          = DateTime.Now;
                    Comp.CreatedOnSpecified = true;
                    Comp.Email              = tt.Email;
                    Comp.EstID              = tt.EstID;
                    Comp.IsActive           = "Y";
                    Comp.IsApproved         = "Y";
                    Comp.logoPath           = tt.logoPath;
                    Comp.Mobile             = tt.Mobile;
                    Comp.Phone              = tt.Phone;
                    Comp.SaleAccId          = tt.SubAgentId > 0 ? tt.SubAgentId : tt.AgentId > 0 ? tt.AgentId : Comp.SaleAccId;
                    Comp.SaleAccIdSpecified = true;
                    Comp.UserName           = tt.UserName;
                    int rtn = dbUser.InsertCompany(Comp);

                    #region Activity Log
                    SMSA_Logs_HI log = new SMSA_Logs_HI();
                    utility.IsSpecifed <SMSA_Logs_HI>(log);
                    log.ActivityBy   = user.Value;
                    log.ActivityDesc = "Add New Company";
                    log.ActivityOn   = DateTime.Now;
                    log.ActivityType = "I";
                    log.ColumnId     = rtn;
                    dbUser.AddActivityLog(log);
                    #endregion

                    if (rtn > 0)
                    {
                        if (Membership.GetUser(tt.UserName) == null)
                        {
                            MembershipCreateStatus status;
                            // Generate a new 12-character password with 1 non-alphanumeric character.
                            //y0t(9ci&xUn^
                            string password = tt.UserName + "123"; //utility.GetUniqueKey(8);//Membership.GeneratePassword(8, 0);
                                                                   // string password = "******";

                            MembershipUser newUser = Membership.CreateUser(tt.UserName, password, tt.UserName, "ok", "ok", true, out status);
                            UserServiceClass.SMIM_UserMst_ST User = new UserServiceClass.SMIM_UserMst_ST();
                            User.UserId    = 0; User.UserName = tt.UserName; User.Email = tt.Email;
                            User.FirstName = tt.ContactPerson; User.OrgId = tt.POrgId.Value; User.CompanyId = rtn;

                            utility.IsSpecifed <UserServiceClass.SMIM_UserMst_ST>(User);
                            int maxValue = db.InsertUser(User);
                        }
                        return(Json(new { success = true, response = "Company registered successfully." }));
                    }
                    else if (rtn == 0)
                    {
                        return(Json(new { success = false, response = "Company already registered." }));
                    }
                    #endregion
                }
            }
            catch (Exception)
            {
                throw;
            }
            var req = tt;
            return(View(tt));
        }