예제 #1
0
        public JsonResult PostUserRole(string id, string c)
        {
            var UserNameGet = db.Users.Where(p => p.CNIC_Number == c).Select(p => p.Name).ToList().SingleOrDefault();
            var GetUserID   = db.Users.Where(p => p.CNIC_Number == c).Select(p => p.Id).ToList().SingleOrDefault();



            if (id == "employee")
            {
                var GetEmployeeID = db.D_Employee.Where(p => p.Userid == GetUserID).Select(p => p.Userid).ToList().SingleOrDefault();
                if (GetEmployeeID != GetUserID)
                {
                    D_Employee employee = new D_Employee
                    {
                        Userid        = GetUserID,
                        Name          = UserNameGet,
                        Employee_Info = "Employee ki info"
                    };

                    if (employee != null)
                    {
                        db.D_Employee.Add(employee);
                        db.SaveChanges();
                        //return Json(employee);
                        return(Json(new  { Success = true, Message = "User Added as Employee" }));
                    }
                    else
                    {
                        return(Json(new { Success = false, Message = "User informmation might be emplty" }));
                    }
                }
                else
                {
                    return(Json(false));
                }
            }
            else if (id == "customer")
            {
                var GetCustomerID = db.D_Customer.Where(p => p.Userid == GetUserID).Select(p => p.Userid).ToList().SingleOrDefault();
                if (GetCustomerID != GetUserID)
                {
                    D_Customer customer = new D_Customer
                    {
                        Userid        = GetUserID,
                        Name          = UserNameGet,
                        Customer_Info = "customer ki info"
                    };

                    if (customer != null)
                    {
                        db.D_Customer.Add(customer);
                        db.SaveChanges();
                        return(Json(new { Success = true, Message = "User Added as Customer" }));
                        //return Json(customer);
                    }
                    else
                    {
                        return(Json(new { Success = false, Message = "User informmation might be emplty" }));
                    }
                }
                else
                {
                    return(Json(false));
                }
            }
            else if (id == "owner")
            {
                var GetOwnerID = db.D_Owner.Where(p => p.Userid == GetUserID).Select(p => p.Userid).ToList().SingleOrDefault();
                if (GetOwnerID != GetUserID)
                {
                    D_Owner owner = new D_Owner
                    {
                        Userid     = GetUserID,
                        Name       = UserNameGet,
                        Owner_Info = "owner ki info"
                    };

                    if (owner != null)
                    {
                        db.D_Owner.Add(owner);
                        db.SaveChanges();
                        //return Json(owner);
                        return(Json(new { Success = true, Message = "User Added as Owner" }));
                    }
                    else
                    {
                        return(Json(new { Success = false, Message = "User informmation might be emplty" }));
                    }
                }
                else
                {
                    return(Json(false));
                }
            }
            else if (id == "supplier")
            {
                var GetSupplierID = db.D_Supplier.Where(p => p.Userid == GetUserID).Select(p => p.Userid).ToList().SingleOrDefault();
                if (GetSupplierID != GetUserID)
                {
                    D_Supplier supplier = new D_Supplier
                    {
                        Userid        = GetUserID,
                        Name          = UserNameGet,
                        Supplier_Info = "supplier ki info"
                    };

                    if (supplier != null)
                    {
                        db.D_Supplier.Add(supplier);
                        db.SaveChanges();
                        //return Json(supplier);
                        return(Json(new { Success = true, Message = "User Added as Supplier" }));
                    }
                    else
                    {
                        return(Json(new { Success = false, Message = "User informmation might be emplty" }));
                    }
                }
                else
                {
                    return(Json(false));
                }
            }
            else
            {
                return(Json(false));
            }
        }
예제 #2
0
        public JsonResult AddSupplier(D_Supplier supp, string id, int?ind_aop_company)

        {
            //var UserIdGet = db.Users.Where(p => p.CNIC_Number == id).Select(p => p.Id).ToList().SingleOrDefault();
            if ((id != "") && (ind_aop_company == null))
            {
                var UserIdGet         = db.Users.Where(p => p.CNIC_Number == id).Select(p => p.Id).ToList().SingleOrDefault();
                var SupplierUserIdGet = db.D_Supplier.Where(p => p.Userid == UserIdGet).Select(p => p.Userid).ToList().SingleOrDefault();
                if (UserIdGet != SupplierUserIdGet)
                {
                    D_Supplier supplier = new D_Supplier
                    {
                        Userid                  = UserIdGet,
                        Name                    = supp.Name,
                        CNIC_Number             = supp.CNIC_Number,
                        Industry                = supp.Industry,
                        Supply_Chain_Role       = supp.Supply_Chain_Role,
                        Business                = supp.Business,
                        Billing_Address         = supp.Billing_Address,
                        Shipping_Address        = supp.Shipping_Address,
                        Billing_Contact_Number  = supp.Billing_Contact_Number,
                        Shipping_Contact_Number = supp.Shipping_Contact_Number,
                        Billing_Email_Id        = supp.Billing_Email_Id,
                        Shipping_Email_Id       = supp.Shipping_Email_Id,
                        Product_Type            = supp.Product_Type,
                        Payment_Method          = supp.Payment_Method
                    };
                    db.D_Supplier.Add(supplier);
                    db.SaveChanges();
                    return(Json(supplier, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    //return Json(new { Success = false, Message = "user as supplier already exist" });
                    return(Json(false));
                }
            }
            else if ((id == "") && (ind_aop_company != null))
            {
                var UserIdGet         = db.Users.Where(p => p.Id == ind_aop_company).Select(p => p.Id).ToList().SingleOrDefault();
                var SupplierUserIdGet = db.D_Supplier.Where(p => p.Userid == UserIdGet).Select(p => p.Userid).ToList().SingleOrDefault();
                if (UserIdGet != SupplierUserIdGet)
                {
                    D_Supplier supplier = new D_Supplier
                    {
                        Userid                  = UserIdGet,
                        Name                    = supp.Name,
                        CNIC_Number             = supp.CNIC_Number,
                        Industry                = supp.Industry,
                        Supply_Chain_Role       = supp.Supply_Chain_Role,
                        Business                = supp.Business,
                        Billing_Address         = supp.Billing_Address,
                        Shipping_Address        = supp.Shipping_Address,
                        Billing_Contact_Number  = supp.Billing_Contact_Number,
                        Shipping_Contact_Number = supp.Shipping_Contact_Number,
                        Billing_Email_Id        = supp.Billing_Email_Id,
                        Shipping_Email_Id       = supp.Shipping_Email_Id,
                        Product_Type            = supp.Product_Type,
                        Payment_Method          = supp.Payment_Method
                    };
                    db.D_Supplier.Add(supplier);
                    db.SaveChanges();
                    return(Json(true));
                }
                else
                {
                    //return Json(new { Success = false, Message = "user as supplier already exist" });
                    return(Json(false));
                }
            }
            else
            {
                return(Json(false));
            }
        }