Exemplo n.º 1
0
        //inserts hanger details into database ,if the addressid is already present in
        //address table it adds the details only in hanger table,manager tables
        //else it adds in address table also
        public static string insertHanger(BindModel bind)
        {
            try
            {
                if (bind.Address.AddressId == null)
                {
                    a.tblManagers.Add(bind.Manager);
                    a.SaveChanges();
                    a.tblHangers.Add(bind.Hanger);
                    a.SaveChanges();
                }
                else
                {
                    a.tblAddresses.Add(bind.Address);
                    a.SaveChanges();
                    a.tblManagers.Add(bind.Manager);
                    a.SaveChanges();
                    a.tblHangers.Add(bind.Hanger);
                    a.SaveChanges();
                }
            }
            catch (DbUpdateException E)
            {
                SqlException S = E.GetBaseException() as SqlException;

                return("Something went wrong, Plz try again.");
            }
            catch (DbEntityValidationException M)
            {
                //SqlException ex = E.GetBaseException() as SqlException;
                return(M.Message);
            }
            return("Hanger Added Successfully " + bind.Hanger.Hanger_ID);
        }
Exemplo n.º 2
0
        //generates addressid based on entered city and houseno,managerid based on socialscurity umber,hangerid based on location
        public static void getIds(BindModel bind)
        {
            var ad = from i in a.tblAddresses
                     where i.HouseNo == bind.Address.HouseNo && i.City == bind.Address.City
                     select i;

            if (ad.Count() == 1)
            {
                bind.Manager.AddressId = ad.First().AddressId;
            }
            else
            {
                ObjectResult <string> ob = a.sp_Address(bind.Address.City);
                List <string>         L2 = ob.ToList();
                if (L2.Count != 0)
                {
                    int ai = int.Parse(L2[0].Substring(3)) + 1;
                    bind.Address.AddressId = bind.Address.City.Substring(0, 3) + string.Format("{0:000}", ai);
                    bind.Manager.AddressId = bind.Address.AddressId;
                }
                else
                {
                    bind.Address.AddressId = bind.Address.City.Substring(0, 3) + "101";
                    bind.Manager.AddressId = bind.Address.AddressId;
                }
            }

            ObjectResult <string> ob1 = a.sp_Hanger(bind.Hanger.HangerLocation);
            List <string>         L   = ob1.ToList();

            if (L.Count != 0)
            {
                int ai = int.Parse(L[0].Substring(3)) + 1;
                bind.Hanger.Hanger_ID = bind.Hanger.HangerLocation.Substring(0, 3) + string.Format("{0:000}", ai);
            }
            else
            {
                bind.Hanger.Hanger_ID = bind.Hanger.HangerLocation.Substring(0, 3) + "101";
            }
            ObjectResult <string> ob2 = a.sp_Manager(bind.Manager.SocialSecurityNo);
            List <string>         L1  = ob2.ToList();

            if (L1.Count != 0)
            {
                int pi = int.Parse(L1[0].Substring(4)) + 1;
                bind.Manager.ManagerId = bind.Manager.SocialSecurityNo.Substring(bind.Manager.SocialSecurityNo.Length - 4, 4) + string.Format("{0:00}", pi);
                bind.Hanger.ManagerId  = bind.Manager.ManagerId;
            }
            else
            {
                bind.Manager.ManagerId = bind.Manager.SocialSecurityNo.Substring(bind.Manager.SocialSecurityNo.Length - 4, 4) + "31";
                bind.Hanger.ManagerId  = bind.Manager.ManagerId;
            }
        }