// to activate Authorization = [AuthorizeRoles(admin,accountant)]
        // to add default route = [Route("x/x/{parameter 1}/{parameter 2}")]
        // to pass parameter by exception = public ActionResult Index( string Id, ClientsViewModel Model)
        public ActionResult Index(ClientsViewModel Model)
        {
            try
            {
                //if (ModelState.IsValid == true)
                //{
                LaunSysDBEntities db = new LaunSysDBEntities();
                //------------------------To populate the drop down lists---------------------------
                List <tb_Titles> TitleList = db.tb_Titles.ToList();
                ViewBag.VTitleLists = new SelectList(TitleList, "TitleID", "Title");

                List <tb_Gender> GenderList = db.tb_Gender.ToList();
                ViewBag.VGenderLists = new SelectList(GenderList, "GenderID", "Gendername");
                //----------------------------------------------------------------------------------



                if (Model.CustID > 0)
                {
                    //UPDATE EXISTING RECORD
                    tb_Customers Clients = db.tb_Customers.SingleOrDefault(x => x.CustID == Model.CustID && x.IsNotActive == false);

                    Clients.TitleID      = Model.TitleID;
                    Clients.SurName      = Model.SurName;
                    Clients.OtherNames   = Model.OtherNames;
                    Clients.GenderID     = Model.GenderID;
                    Clients.Cust_Address = Model.Cust_Address;
                    Clients.Phone        = Model.Phone;
                    Clients.Email        = Model.Email;
                    Clients.CreatedDate  = Model.CreatedDate;
                    db.SaveChanges();
                }

                else
                {
                    //INSERT NEW RECORD
                    tb_Customers Clients = new tb_Customers();
                    Clients.TitleID      = Model.TitleID;
                    Clients.SurName      = Model.SurName;
                    Clients.OtherNames   = Model.OtherNames;
                    Clients.GenderID     = Model.GenderID;
                    Clients.Cust_Address = Model.Cust_Address;
                    Clients.Phone        = Model.Phone;
                    Clients.Email        = Model.Email;
                    Clients.CreatedDate  = Model.CreatedDate;
                    Clients.IsNotActive  = false;


                    db.tb_Customers.Add(Clients);
                    db.SaveChanges();
                }
                return(View(Model));
                //}
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ActionResult Index(IncomesViewModel Model)
        {
            try
            {
                //LaunSysDBEntities db = new LaunSysDBEntities();
                //if (ModelState.IsValid == true)
                //{

                //------------------------To populate the drop down lists---------------------------

                //List<tb_Branch> BranchList = db.tb_Branch.ToList();
                //ViewBag.VBranchLists = new SelectList(BranchList, "BranchId", "Branchname");

                //List<tb_Status> StatusList = db.tb_Status.ToList();
                //ViewBag.VStatusLists = new SelectList(StatusList, "StatusId", "Status");
                AllDropDown();
                ////----------------------------------------------------------------------------------
                if (Model.Id > 0)
                {
                    //UPDATE EXISTING RECORD
                    tb_Income IncomeData = db.tb_Income.SingleOrDefault(x => x.Id == Model.Id && x.tb_Status.Status == true);

                    IncomeData.Id          = Model.Id;
                    IncomeData.Date        = Model.Date;
                    IncomeData.Inc_SN      = Model.Inc_SN;
                    IncomeData.Description = Model.Description;
                    IncomeData.Inv_No      = Model.Inv_No;
                    IncomeData.Amount      = Model.Amount;
                    IncomeData.BranchId    = Model.BranchId;
                    IncomeData.StatusId    = Model.StatusId;
                    db.SaveChanges();
                }

                else
                {
                    //INSERT NEW RECORD
                    tb_Income IncomeData = new tb_Income();
                    IncomeData.Id          = Model.Id;
                    IncomeData.Date        = Model.Date;
                    IncomeData.Inc_SN      = Model.Inc_SN;
                    IncomeData.Description = Model.Description;
                    IncomeData.Inv_No      = Model.Inv_No;
                    IncomeData.Amount      = Model.Amount;
                    IncomeData.BranchId    = Model.BranchId;
                    IncomeData.StatusId    = Model.StatusId;

                    db.tb_Income.Add(IncomeData);
                    db.SaveChanges();
                }
                return(View(Model));
                //}
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public JsonResult InsertCustomers(CustomersViewModel model)
        {
            var result = false;

            try
            {
                if (model.CustID > 0)
                {
                    tb_Customers Cust = db.tb_Customers.SingleOrDefault(x => x.IsNotActive == false && x.CustID == model.CustID);
                    Cust.TitleID      = model.TitleID;
                    Cust.SurName      = model.SurName;
                    Cust.OtherNames   = model.OtherNames;
                    Cust.GenderID     = model.GenderID;
                    Cust.Cust_Address = model.Cust_Address;
                    Cust.Phone        = model.Phone;
                    Cust.Email        = model.Email;
                    Cust.CreatedDate  = model.CreatedDate;
                    //Cust.IsNotActive = false;
                    //3077145452
                    db.SaveChanges();
                    result = true;
                }
                else
                {
                    tb_Customers Cust = new tb_Customers();

                    Cust.TitleID      = model.TitleID;
                    Cust.SurName      = model.SurName;
                    Cust.OtherNames   = model.OtherNames;
                    Cust.GenderID     = model.GenderID;
                    Cust.Cust_Address = model.Cust_Address;
                    Cust.Phone        = model.Phone;
                    Cust.Email        = model.Email;
                    Cust.CreatedDate  = model.CreatedDate;
                    Cust.IsNotActive  = false;

                    db.tb_Customers.Add(Cust);
                    db.SaveChanges();
                    result = true;
                }

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ActionResult Index(ExpensesViewModel Model)
        {
            try
            {
                AllDropDowns();

                //TO UPDATE EXISITING RECORD
                if (Model.Id > 0)
                {
                    tb_Expenses ExpensesData = db.tb_Expenses.SingleOrDefault(x => x.Id == Model.Id && x.tb_Status.Status == true);
                    ExpensesData.Id          = Model.Id;
                    ExpensesData.Date        = Model.Date;
                    ExpensesData.Exp_SN      = Model.Exp_SN;
                    ExpensesData.Description = Model.Description;
                    ExpensesData.Inv_No      = Model.Inv_No;
                    ExpensesData.Amount      = Model.Amount;
                    ExpensesData.BranchId    = Model.BranchId;
                    ExpensesData.StatusId    = Model.StatusId;

                    db.SaveChanges();
                }
                else
                { //TO INSERT NEW EXPENSES DATA
                    tb_Expenses ExpensesData = new tb_Expenses();
                    ExpensesData.Id          = Model.Id;
                    ExpensesData.Date        = Model.Date;
                    ExpensesData.Exp_SN      = Model.Exp_SN;
                    ExpensesData.Description = Model.Description;
                    ExpensesData.Inv_No      = Model.Inv_No;
                    ExpensesData.Amount      = Model.Amount;
                    ExpensesData.BranchId    = Model.BranchId;
                    ExpensesData.StatusId    = Model.StatusId;
                    db.tb_Expenses.Add(ExpensesData);
                    db.SaveChanges();
                }

                return(View(Model));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        //-----------------------------Delete client----------------------------
        public JsonResult DeleteClient(int CustID)
        {
            LaunSysDBEntities db = new LaunSysDBEntities();
            bool         result  = false;
            tb_Customers Cust    = db.tb_Customers.SingleOrDefault(x => x.IsNotActive == false && x.CustID == CustID);

            if (Cust != null)
            {
                //set the customer id to true, there fore hide it from the table\
                Cust.IsNotActive = true;
                db.SaveChanges();
                result = true;
            }

            //FlashMessage.Info("Invalid Login Details");
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Beispiel #6
0
        //-----------------------------Delete User----------------------------
        public JsonResult DeleteUser(int UserId)
        {
            LaunSysDBEntities db = new LaunSysDBEntities();
            bool     result      = false;
            tb_Users User        = db.tb_Users.SingleOrDefault(x => x.StatusId == 1 && x.UserId == UserId);

            /// tb_Users User = db.tb_Users.SingleOrDefault(x => x.tb_Status.Status == true && x.UserId == UserId);

            if (User != null)
            {
                //set the customer id to true, there fore hide it from the table\
                //User.tb_Status.Status = false;
                User.StatusId = 2;
                db.SaveChanges();
                result = true;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        //-----------------------------Delete Income----------------------------
        public JsonResult DeleteIncome(int Id)
        {
            LaunSysDBEntities db = new LaunSysDBEntities();
            bool result          = false;
            //tb_Income Income = db.tb_Income.SingleOrDefault(x => x.StatusId == 1 && x.Id == Id);
            tb_Income Income = db.tb_Income.SingleOrDefault
                                   (x => x.tb_Status.Status == true && x.Id == Id);


            if (Income != null)
            {
                //set the customer id to true, there fore hide it from the table\
                // Income.tb_Status.Status = false;
                Income.StatusId = 2;
                db.SaveChanges();
                result = true;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Beispiel #8
0
        public JsonResult SaveIncomingfabric(IncomingFabricsViewModel IncfabricData)
        {
            bool status = false;

            //if (ModelState.IsValid)
            //{

            //------------------alternatively--------------

            //tb_Incoming_Fabrics incFab = new tb_Incoming_Fabrics();

            //incFab.BranchId = IncfabricData.BranchId;
            //incFab.Branch_Name = IncfabricData.Branchname;
            //incFab.CustomerId = IncfabricData.CustomerId;
            //incFab.Customer_Name = IncfabricData.Customer_Name;
            //incFab.Date_Recorded = DateTime.Now;
            //incFab.Receipt_No = IncfabricData.Receipt_No;
            //incFab.Total_Amt = IncfabricData.Total_Amt;
            //incFab.Recorded_By = Session["Email"].ToString();

            //db.tb_Incoming_Fabrics.Add(incFab);

            //foreach (var IndFab in IncfabricData.Incoming_Fabric_Desc)
            //{
            //    IndFab.IncFabId = incFab.IncFabId;
            //    incFab.tb_Incoming_Fabric_Desc.Add(IndFab);
            //}
            //db.tb_Incoming_Fabrics.Add(incFab);
            //db.SaveChanges();
            //status = true;

            //------------------end of alternatively--------------
            using (LaunSysDBEntities IncFabDetail = new LaunSysDBEntities())
            {
                tb_Incoming_Fabrics FabInfo = new tb_Incoming_Fabrics
                {
                    BranchId = IncfabricData.BranchId,
                    //Branch_Name = IncfabricData.Branch_Name,
                    CustomerId = IncfabricData.CustomerId,
                    //Customer_Name = IncfabricData.Customer_Name,
                    Date_Recorded = DateTime.Now,
                    Receipt_No    = IncfabricData.Receipt_No,
                    Total_Amt     = IncfabricData.Total_Amt,
                    Recorded_By   = Session["Email"].ToString(),
                };
                //tb_Incoming_Fabrics FabInfo = new tb_Incoming_Fabrics
                //{
                //    CustomerId = 990
                //};
                IncFabDetail.tb_Incoming_Fabrics.Add(FabInfo);
                IncFabDetail.SaveChanges();

                foreach (var IndfabDetail in IncfabricData.Incoming_Fabric_Desc)
                {
                    //FabInfo.tb_Incoming_Fabric_Desc.Add(IndfabDetail);

                    IndfabDetail.IncFabId = FabInfo.IncFabId;
                    IncFabDetail.tb_Incoming_Fabric_Desc.Add(IndfabDetail);
                }

                //IncFabDetail.tb_Incoming_Fabrics.Add(FabInfo);
                //tb_Incoming_Fabric_Desc FabDescription = new tb_Incoming_Fabric_Desc()
                //{
                //    Description = IncfabricData.Incoming_Fabric_Desc.
                //};
                //IncFabDetail.tb_Incoming_Fabric_Desc.Add()

                //IncFabDetail.tb_Incoming_Fabrics.Add(FabInfo);
                IncFabDetail.SaveChanges();
                status = true;
            }
            //----------------------------------------------------------

            //using (LaunSysDBEntities IncFabDetail = new LaunSysDBEntities())
            //    {
            //        tb_Incoming_Fabrics FabInfo = new tb_Incoming_Fabrics
            //        {
            //            BranchId = IncfabricData.BranchId,
            //            Branch_Name = IncfabricData.Branch_Name,
            //            CustomerId = IncfabricData.CustomerId,
            //            Customer_Name = IncfabricData.Customer_Name,
            //            Date_Recorded = DateTime.Now,
            //            Receipt_No = IncfabricData.Receipt_No,
            //            Total_Amt = IncfabricData.Total_Amt,
            //            Recorded_By = Session["Email"].ToString(),
            //        };


            //    IncFabDetail.tb_Incoming_Fabrics.Add(FabInfo);
            //    IncFabDetail.SaveChanges();
            //    int X = FabInfo.IncFabId;

            //        foreach(var IndfabDetail in IncfabricData.Incoming_Fabric_Desc)

            //        {
            //        IndfabDetail.IncFabId = X;
            //        FabInfo.tb_Incoming_Fabric_Desc.Add(IndfabDetail);
            //        IncFabDetail.SaveChanges();
            //        };

            //        status = true;
            //    }
            //-----------------------------------------------another---------------------
            //}

            //else
            //{
            //    status = false;
            //}


            return(new JsonResult {
                Data = new { status = status }
            });
        }
Beispiel #9
0
        public ActionResult Index(UsersViewModel Model)
        {
            try
            {
                //if (ModelState.IsValid == true)
                //{
                LaunSysDBEntities db = new LaunSysDBEntities();
                //------------------------To populate the drop down lists---------------------------

                List <tb_Role> RoleList = db.tb_Role.ToList();
                ViewBag.VRoleLists = new SelectList(RoleList, "RoleId", "Rolename");

                List <tb_Division> DivisionList = db.tb_Division.ToList();
                ViewBag.VDivisionLists = new SelectList(DivisionList, "DivisionId", "Divisionname");

                List <tb_Branch> BranchList = db.tb_Branch.ToList();
                ViewBag.VBranchLists = new SelectList(BranchList, "BranchId", "Branchname");

                List <tb_Department> DeptList = db.tb_Department.ToList();
                ViewBag.VDeptLists = new SelectList(DeptList, "DeptId", "Deptname");

                List <tb_Status> StatusList = db.tb_Status.ToList();
                ViewBag.VStatusLists = new SelectList(StatusList, "StatusId", "Status");
                //----------------------------------------------------------------------------------



                if (Model.UserId > 0)
                {
                    //UPDATE EXISTING RECORD
                    tb_Users Users = db.tb_Users.SingleOrDefault(x => x.UserId == Model.UserId && x.tb_Status.Status == true);

                    Users.UserId     = Model.UserId;
                    Users.Email      = Model.Email;
                    Users.Password   = Model.Password;
                    Users.RoleId     = Model.RoleId;
                    Users.DivisionId = Model.DivisionId;
                    Users.BranchId   = Model.BranchId;
                    Users.DeptId     = Model.DeptId;
                    Users.StatusId   = Model.StatusId;
                    db.SaveChanges();
                }

                else
                {
                    //INSERT NEW RECORD
                    tb_Users Users = new tb_Users();
                    Users.UserId = Model.UserId;
                    Users.Email  = Model.Email;



                    var pass = System.Text.Encoding.UTF8.GetBytes(Model.Password);
                    Users.Password = Convert.ToBase64String(pass);

                    // Users.Password = Model.Password;

                    Users.RoleId     = Model.RoleId;
                    Users.DivisionId = Model.DivisionId;
                    Users.BranchId   = Model.BranchId;
                    Users.DeptId     = Model.DeptId;
                    Users.StatusId   = Model.StatusId;



                    db.tb_Users.Add(Users);
                    db.SaveChanges();
                }
                return(View(Model));
                //}
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }