Exemple #1
0
 public JsonResult GetAllModule()
 {
     try
     {
         decimal id      = SessionManger.WorkShopOfLoggedInUser(Session);
         string  user_id = User.Identity.GetUserId();
         var     result  = unitOfWork.ModuleRepository.Get()
                           .Select(a => new
         {
             a.ModuleId,
             a.ModuleName,
             a.ModuleIcon,
             action = a.tblActions.Where(b => b.IsInMenu == true && b.tblUserActionMappings.Where(am => am.user_id == user_id && am.is_permitted == 1).Any())
                      .Select(ac
                              => new
             {
                 ac.ActionId,
                 ac.ActionName,
                 ac.ActionDisplayName,
                 ac.ActionUrl
             }
                              ).ToList()
         }).Where(a => a.action.Count() > 0).ToList();
         return(Json(new { result = result, success = true }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #2
0
        public ActionResult AddStore(VM_Store store)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    tblStore aStore = new tblStore();
                    aStore.StoreName       = store.StoreName;
                    aStore.WorkShopId      = Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                    aStore.CreatedBy       = SessionManger.LoggedInUser(Session);
                    aStore.CreatedDateTime = DateTime.Now;
                    aStore.EditedBy        = null;
                    aStore.EditedDateTime  = null;

                    unitOfWork.StoreRepository.Insert(aStore);
                    unitOfWork.Save();

                    return(Json(new { success = true, successMessage = "Store Save Successfully" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { success = false, errorMessage = "Store not Save" }, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult AddRoute(VM_Route route)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    tblRoute aRoute = new tblRoute();
                    aRoute.RouteName       = route.RouteName;
                    aRoute.WorkShopId      = Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                    aRoute.CreatedBy       = SessionManger.LoggedInUser(Session);
                    aRoute.CreatedDateTime = DateTime.Now;
                    aRoute.EditedBy        = null;
                    aRoute.EditedDateTime  = null;

                    unitOfWork.RouteRepository.Insert(aRoute);
                    unitOfWork.Save();

                    return(Json(new { success = true, successMessage = "Bus Route Added Successfully." }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { success = false, errorMessage = "Model is not Valid" }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult AddSupplier(VM_Supplier supplier)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    tblSupplier aSupplier = new tblSupplier();

                    aSupplier.CompanyName     = supplier.CompanyName;
                    aSupplier.Address         = supplier.Address;
                    aSupplier.ContactNo       = supplier.ContactNo;
                    aSupplier.WorkShopId      = Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                    aSupplier.CreatedBy       = SessionManger.LoggedInUser(Session);
                    aSupplier.CreatedDateTime = DateTime.Now;
                    aSupplier.EditedBy        = null;
                    aSupplier.EditedDateTime  = null;

                    unitOfWork.SupplierRepository.Insert(aSupplier);
                    unitOfWork.Save();

                    return(Json(new { success = true, successMessage = "Supplier Added Successfully!" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    return(Json(new { success = false, errorMessage = ex }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { success = false, errorMessage = "Fill Up all required filled" }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult AddAction(VM_Action ViewAction)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    tblAction aAction = new tblAction();

                    aAction.ActionName        = ViewAction.ActionName;
                    aAction.ActionDisplayName = ViewAction.ActionDisplayName;
                    aAction.ActionUrl         = ViewAction.ActionUrl;
                    aAction.ModuleId          = ViewAction.ModuleId;
                    aAction.IsInMenu          = ViewAction.IsInMenu;
                    aAction.IsView            = ViewAction.IsView;
                    aAction.WorkShopId        = Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                    aAction.CreatedBy         = SessionManger.LoggedInUser(Session);
                    aAction.CreatedDateTime   = DateTime.Now;
                    aAction.EditedBy          = null;
                    aAction.EditedDateTime    = null;

                    unitOfWork.ActionRepository.Insert(aAction);
                    unitOfWork.Save();

                    return(Json(new { success = true, successMessage = "Action Added Successfully!" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    return(Json(new { success = false, errorMessage = ex }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { success = false, errorMessage = "Fill Up all required filled" }, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #6
0
        public JsonResult AddPartsInfo(VM_PartsInfo partsInfo)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    tblPartsInfo aPartsInfo = new tblPartsInfo();

                    aPartsInfo.PartsName       = partsInfo.PartsName;
                    aPartsInfo.BasePrice       = partsInfo.BasePrice;
                    aPartsInfo.WorkShopId      = Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                    aPartsInfo.CreatedBy       = SessionManger.LoggedInUser(Session);
                    aPartsInfo.CreatedDateTime = DateTime.Now;
                    aPartsInfo.EditedBy        = null;
                    aPartsInfo.EditedDateTime  = null;

                    unitOfWork.PartsInfoRepository.Insert(aPartsInfo);
                    unitOfWork.Save();

                    return(Json(new { success = true, successMessage = "Parts Information Added Successfully!" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { success = false, errorMessage = "Fill Up all required filled" }, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #7
0
        public JsonResult AddModule(VM_Module module)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    tblModule aModule = new tblModule();

                    aModule.ModuleName      = module.ModuleName;
                    aModule.ModuleOrder     = module.ModuleOrder;
                    aModule.ModuleIcon      = module.ModuleIcon;
                    aModule.WorkShopId      = Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                    aModule.CreatedBy       = SessionManger.LoggedInUser(Session);
                    aModule.CreatedDateTime = DateTime.Now;
                    aModule.EditedBy        = null;
                    aModule.EditedDateTime  = null;

                    unitOfWork.ModuleRepository.Insert(aModule);
                    unitOfWork.Save();

                    return(Json(new { success = true, successMessage = "Module Added Successfully!" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    return(Json(new { success = false, errorMessage = ex }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { success = false, errorMessage = "Fill Up all required filled" }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult UserMenuActionForPermission(string userId)
        {
            //decimal id = SessionManger.BrokerOfLoggedInUser(Session).membership_id;
            decimal workShopId = SessionManger.WorkShopOfLoggedInUser(Session);

            //string user_id = User.Identity.GetUserId();
            //var views = userActionMappingFactory.GetAll().Where(a => a.user_id == user_id)
            //    .Select(x => x.action_id).ToList();
            var data = unitOfWork.ModuleRepository.Get()
                       .Select(a => new
            {
                a.ModuleId,
                label    = a.ModuleName,
                children = a.tblActions.Where(x => x.IsInMenu == true)
                           .Select(ac
                                   => new
                {
                    ac.ActionId,
                    label = ac.ActionDisplayName,
                    //a.membership_id,
                    selected = ac.tblUserActionMappings.Where(x => x.user_id == userId).Select(x => x.user_id).FirstOrDefault() == null ? false : true
                }
                                   ).ToList()
            }).ToList();

            return(Json(new { success = true, result = data }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult AddDesignation(VM_Designation designation)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    tblDesignation aDesignation = new tblDesignation();
                    aDesignation.DesignationName = designation.DesignationName;
                    aDesignation.WorkShopId      = Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                    aDesignation.CreatedBy       = SessionManger.LoggedInUser(Session);
                    aDesignation.CreatedDateTime = DateTime.Now;
                    aDesignation.EditedBy        = null;
                    aDesignation.EditedDateTime  = null;

                    unitOfWork.DesignationRepository.Insert(aDesignation);
                    unitOfWork.Save();

                    return(Json(new { success = true, successMessage = "Designation Save Successfully" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    return(Json(new { success = false, errorMessage = ex }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { success = false, errorMessage = "Designation not Save" }, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult AddBusInformation(VM_BusInformation busInformation)
        {
            if (ModelState.IsValid)
            {
                var RegistrationNoExist =
                    unitOfWork.BusInformationRepository.Get()
                    .Where(a => a.RegistrationNo == busInformation.RegistrationNo).ToList();

                if (!RegistrationNoExist.Any())
                {
                    try
                    {
                        tblBusInformation abusBusInformation = new tblBusInformation();
                        abusBusInformation.RegistrationNo  = busInformation.RegistrationNo;
                        abusBusInformation.ModelNo         = busInformation.ModelNo;
                        abusBusInformation.ChassisNo       = busInformation.ChassisNo;
                        abusBusInformation.RouteId         = busInformation.RouteId;
                        abusBusInformation.WorkShopId      = Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                        abusBusInformation.CreatedBy       = SessionManger.LoggedInUser(Session);
                        abusBusInformation.CreatedDateTime = DateTime.Now;
                        abusBusInformation.EditedBy        = null;
                        abusBusInformation.EditedDateTime  = null;

                        unitOfWork.BusInformationRepository.Insert(abusBusInformation);
                        unitOfWork.Save();

                        return(Json(new { success = true, successMessage = "Bus Information Saved Successfully" },
                                    JsonRequestBehavior.AllowGet));
                    }
                    catch (Exception ex)
                    {
                        return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    return(Json(new { success = false, errorMessage = "Registration No already exist" }, JsonRequestBehavior.AllowGet));
                }
            }

            else
            {
                return(Json(new { success = false, errorMessage = "Bus Information not Saved" }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult SaveUserPermission(decimal[] id, string userId)
        {
            //userActionMappingFactory = new UserActionMappingFactory();
            //actionFactory = new ActionFactory();
            try
            {
                List <tblAction> actions = new List <tblAction>();
                actions = unitOfWork.ActionRepository.Get().ToList();

                List <tblUserActionMapping> actionMappings = new List <tblUserActionMapping>();
                actionMappings = unitOfWork.UserActonMappingRepository.Get().Where(a => a.user_id == userId).ToList();

                foreach (var items in actionMappings)
                {
                    unitOfWork.UserActonMappingRepository.Delete(items);
                }

                if (id != null)
                {
                    foreach (var items in id)
                    {
                        tblUserActionMapping actionMapping = new tblUserActionMapping();
                        actionMapping.action_id       = Int32.Parse(items.ToString());
                        actionMapping.user_id         = userId;
                        actionMapping.is_permitted    = 1;
                        actionMapping.WorkShopId      = Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                        actionMapping.CreatedBy       = SessionManger.LoggedInUser(Session);
                        actionMapping.CreatedDateTime = DateTime.Now;
                        actionMapping.EditedBy        = null;
                        actionMapping.EditedDateTime  = null;
                        unitOfWork.UserActonMappingRepository.Insert(actionMapping);
                    }
                }
                unitOfWork.Save();

                return(Json(new { success = true, successMessage = "Mapped Successfully" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult GetAllUserForCurrentAgency()
        {
            decimal workShopId = SessionManger.WorkShopOfLoggedInUser(Session);

            try
            {
                //var users = DropDown.ddlUsers(membershipId);
                var users = unitOfWork.WorkShopUserRepository.Get().Where(x => x.workShop_id == workShopId).Select(
                    a => new
                {
                    text  = a.AspNetUser.UserName,
                    value = a.UserId
                }).ToList();

                return(Json(new { success = true, result = users }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception exception)
            {
                return(Json(new { success = false, errorMessage = exception.Message }, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult AddPartsInStore(DateTime addDate, IEnumerable <VM_PartsTransfer> addPartInStore)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    tblPartsTransfer aPartsTransfer = new tblPartsTransfer();
                    foreach (VM_PartsTransfer bPartsTransfer in addPartInStore)
                    {
                        aPartsTransfer.StoreId    = bPartsTransfer.StoreId;
                        aPartsTransfer.Date       = addDate;
                        aPartsTransfer.PartsId    = bPartsTransfer.PartsId;
                        aPartsTransfer.Quantity   = bPartsTransfer.Quantity;
                        aPartsTransfer.UnitPrice  = bPartsTransfer.UnitPrice;
                        aPartsTransfer.Price      = bPartsTransfer.Quantity * bPartsTransfer.UnitPrice;
                        aPartsTransfer.isIn       = true;
                        aPartsTransfer.isOut      = false;
                        aPartsTransfer.WorkShopId =
                            Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                        aPartsTransfer.CreatedBy       = SessionManger.LoggedInUser(Session);
                        aPartsTransfer.CreatedDateTime = DateTime.Now;
                        aPartsTransfer.EditedBy        = null;
                        aPartsTransfer.EditedDateTime  = null;


                        unitOfWork.PartsTransferRepository.Insert(aPartsTransfer);
                        unitOfWork.Save();
                    }
                    return(Json(new { success = true, successMessage = "Parts  Added Successfully in Store." }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { success = false, errorMessage = "Model is not valid" }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult GenerateReportForSearchResult(int routeId)
        {
            try
            {
                List <DAL.ViewModel.VM_BusInformation> busInfoList = unitOfWork.CustomRepository.sp_BusInformationListForABusRoute((routeId));
                var newBusInfoList = new List <DAL.ViewModel.VM_BusInformation>();
                foreach (var busInfo in busInfoList)
                {
                    DAL.ViewModel.VM_BusInformation newBusInfo = new DAL.ViewModel.VM_BusInformation();
                    newBusInfo.RegistrationNo = busInfo.RegistrationNo;
                    newBusInfo.ModelNo        = busInfo.ModelNo;
                    newBusInfo.ChassisNo      = busInfo.ChassisNo;
                    newBusInfoList.Add(newBusInfo);
                }
                int    workShopId      = Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                string workShopName    = unitOfWork.WorkShopInformationRepository.GetByID(workShopId).Name;
                string workShopAddress = unitOfWork.WorkShopInformationRepository.GetByID(workShopId).Address;
                string routerName      = unitOfWork.RouteRepository.GetByID(routeId).RouteName;

                LocalReport localReport = new LocalReport();
                localReport.ReportPath = Server.MapPath("~/Reports/BusInfornationListForSpecificBusRouteReport.rdlc");
                localReport.SetParameters(new ReportParameter("RouterName", routerName.ToString()));
                localReport.SetParameters(new ReportParameter("WorkShopName", workShopName));
                localReport.SetParameters(new ReportParameter("WorkShopAddress", workShopAddress));
                ReportDataSource reportDataSource = new ReportDataSource("BusInfornationListForSpecificBusRouteDataSet", newBusInfoList);

                localReport.DataSources.Add(reportDataSource);
                string reportType = "pdf";
                string mimeType;
                string encoding;
                string fileNameExtension;
                //The DeviceInfo settings should be changed based on the reportType
                //http://msdn.microsoft.com/en-us/library/ms155397.aspx
                string deviceInfo =
                    "<DeviceInfo>" +
                    "  <OutputFormat>PDF</OutputFormat>" +
                    "  <PageWidth>8.5in</PageWidth>" +
                    "  <PageHeight>11in</PageHeight>" +
                    "  <MarginTop>0.5in</MarginTop>" +
                    "  <MarginLeft>0in</MarginLeft>" +
                    "  <MarginRight>0in</MarginRight>" +
                    "  <MarginBottom>0.1in</MarginBottom>" +
                    "</DeviceInfo>";
                Warning[] warnings;
                string[]  streams;
                byte[]    renderedBytes;
                //Render the report
                renderedBytes = localReport.Render(
                    reportType,
                    deviceInfo,
                    out mimeType,
                    out encoding,
                    out fileNameExtension,
                    out streams,
                    out warnings);
                var path   = System.IO.Path.Combine(Server.MapPath("~/pdfReport"));
                var saveAs = string.Format("{0}.pdf", Path.Combine(path, "myfilename"));

                var idx = 0;
                while (System.IO.File.Exists(saveAs))
                {
                    idx++;
                    saveAs = string.Format("{0}.{1}.pdf", Path.Combine(path, "myfilename"), idx);
                }
                Session["report"] = saveAs;
                using (var stream = new FileStream(saveAs, FileMode.Create, FileAccess.Write))
                {
                    stream.Write(renderedBytes, 0, renderedBytes.Length);
                    stream.Close();
                }
                localReport.Dispose();
                return(Json(new { success = true, successMessage = "Report generated successfully.", result = busInfoList }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #15
0
        //public ActionResult AddPriceForPartsFromSupplier(string registrationNo, DateTime buyDate, IEnumerable<VM_BuyPartsFromSupplier> buyPartsFromSupplier, string other, int? price)
        //{



        //    if (ModelState.IsValid)
        //    {
        //        try
        //        {
        //            if (buyPartsFromSupplier==null)
        //            {

        //                tblBuyPartsFromSupplier bBuyPartsFromSupplier = new tblBuyPartsFromSupplier();

        //                bBuyPartsFromSupplier.RegistrationNo = registrationNo;
        //                bBuyPartsFromSupplier.BuyDate = buyDate;
        //                bBuyPartsFromSupplier.PartsId = null;
        //                bBuyPartsFromSupplier.SupplierId = null;
        //                bBuyPartsFromSupplier.Quantity = null;
        //                bBuyPartsFromSupplier.UnitPrice = null;
        //                bBuyPartsFromSupplier.Other = other;
        //                bBuyPartsFromSupplier.Price = price;
        //                bBuyPartsFromSupplier.WorkShopId =
        //                    Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
        //                bBuyPartsFromSupplier.CreatedBy = SessionManger.LoggedInUser(Session);
        //                bBuyPartsFromSupplier.CreatedDateTime = DateTime.Now;
        //                bBuyPartsFromSupplier.EditedBy = null;
        //                bBuyPartsFromSupplier.EditedDateTime = null;

        //                unitOfWork.BuyPartsFromSupplierRepository.Insert(bBuyPartsFromSupplier);
        //                unitOfWork.Save();

        //            }

        //            else
        //            {
        //                tblBuyPartsFromSupplier aBuyPartsFromSupplier = new tblBuyPartsFromSupplier();
        //                foreach (VM_BuyPartsFromSupplier buyPartsFromSuppliers in buyPartsFromSupplier)
        //                {



        //                    aBuyPartsFromSupplier.RegistrationNo = registrationNo;
        //                    aBuyPartsFromSupplier.BuyDate = buyDate;
        //                    aBuyPartsFromSupplier.PartsId = buyPartsFromSuppliers.PartsId;
        //                    aBuyPartsFromSupplier.SupplierId = buyPartsFromSuppliers.SupplierId;
        //                    aBuyPartsFromSupplier.Quantity = buyPartsFromSuppliers.Quantity;
        //                    aBuyPartsFromSupplier.UnitPrice = buyPartsFromSuppliers.UnitPrice;
        //                    aBuyPartsFromSupplier.Other = null;
        //                    aBuyPartsFromSupplier.Price = buyPartsFromSuppliers.Price;
        //                    aBuyPartsFromSupplier.WorkShopId =
        //                        Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
        //                    aBuyPartsFromSupplier.CreatedBy = SessionManger.LoggedInUser(Session);
        //                    aBuyPartsFromSupplier.CreatedDateTime = DateTime.Now;
        //                    aBuyPartsFromSupplier.EditedBy = null;
        //                    aBuyPartsFromSupplier.EditedDateTime = null;


        //                    unitOfWork.BuyPartsFromSupplierRepository.Insert(aBuyPartsFromSupplier);
        //                    unitOfWork.Save();
        //                }

        //                if (other != null || price != null)
        //                {
        //                    aBuyPartsFromSupplier.RegistrationNo = registrationNo;
        //                    aBuyPartsFromSupplier.BuyDate = buyDate;
        //                    aBuyPartsFromSupplier.PartsId = null;
        //                    aBuyPartsFromSupplier.SupplierId = null;
        //                    aBuyPartsFromSupplier.Quantity = null;
        //                    aBuyPartsFromSupplier.UnitPrice = null;
        //                    aBuyPartsFromSupplier.Other = other;
        //                    aBuyPartsFromSupplier.Price = price;
        //                    aBuyPartsFromSupplier.WorkShopId =
        //                        Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
        //                    aBuyPartsFromSupplier.CreatedBy = SessionManger.LoggedInUser(Session);
        //                    aBuyPartsFromSupplier.CreatedDateTime = DateTime.Now;
        //                    aBuyPartsFromSupplier.EditedBy = null;
        //                    aBuyPartsFromSupplier.EditedDateTime = null;

        //                    unitOfWork.BuyPartsFromSupplierRepository.Insert(aBuyPartsFromSupplier);
        //                    unitOfWork.Save();
        //                }
        //            }

        //            return Json(new { success = true, successMessage = " Added Successfully!" }, JsonRequestBehavior.AllowGet);

        //        }
        //        catch (Exception ex)
        //        {
        //            return Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet);
        //        }
        //    }
        //    else
        //    {
        //        return Json(new { success = false, errorMessage = "Model is not valid" }, JsonRequestBehavior.AllowGet);
        //    }


        //}


        public ActionResult AddPriceForPartsFromSupplier(string registrationNo, DateTime buyDate, IEnumerable <VM_BuyPartsFromSupplier> buyPartsFromSupplier, IEnumerable <VM_BuyPartsFromSupplier> otherExpense)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (buyPartsFromSupplier == null)
                    {
                        tblBuyPartsFromSupplier bBuyPartsFromSupplier = new tblBuyPartsFromSupplier();
                        foreach (VM_BuyPartsFromSupplier otherExpenses in otherExpense)
                        {
                            bBuyPartsFromSupplier.RegistrationNo = registrationNo;
                            bBuyPartsFromSupplier.BuyDate        = buyDate;
                            bBuyPartsFromSupplier.PartsId        = null;
                            bBuyPartsFromSupplier.SupplierId     = null;
                            bBuyPartsFromSupplier.Quantity       = null;
                            bBuyPartsFromSupplier.UnitPrice      = null;
                            bBuyPartsFromSupplier.Other          = otherExpenses.Other;
                            bBuyPartsFromSupplier.Price          = otherExpenses.Price;
                            bBuyPartsFromSupplier.StoreId        = null;
                            bBuyPartsFromSupplier.WorkShopId     =
                                Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                            bBuyPartsFromSupplier.CreatedBy       = SessionManger.LoggedInUser(Session);
                            bBuyPartsFromSupplier.CreatedDateTime = DateTime.Now;
                            bBuyPartsFromSupplier.EditedBy        = null;
                            bBuyPartsFromSupplier.EditedDateTime  = null;

                            unitOfWork.BuyPartsFromSupplierRepository.Insert(bBuyPartsFromSupplier);
                            unitOfWork.Save();
                        }
                    }

                    else
                    {
                        tblBuyPartsFromSupplier aBuyPartsFromSupplier = new tblBuyPartsFromSupplier();
                        foreach (VM_BuyPartsFromSupplier buyPartsFromSuppliers in buyPartsFromSupplier)
                        {
                            aBuyPartsFromSupplier.RegistrationNo = registrationNo;
                            aBuyPartsFromSupplier.BuyDate        = buyDate;
                            aBuyPartsFromSupplier.PartsId        = buyPartsFromSuppliers.PartsId;
                            aBuyPartsFromSupplier.SupplierId     = buyPartsFromSuppliers.SupplierId;
                            aBuyPartsFromSupplier.Quantity       = buyPartsFromSuppliers.Quantity;
                            aBuyPartsFromSupplier.UnitPrice      = buyPartsFromSuppliers.UnitPrice;
                            aBuyPartsFromSupplier.Other          = null;
                            aBuyPartsFromSupplier.StoreId        = null;
                            aBuyPartsFromSupplier.Price          = buyPartsFromSuppliers.Quantity * buyPartsFromSuppliers.UnitPrice;
                            aBuyPartsFromSupplier.WorkShopId     =
                                Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                            aBuyPartsFromSupplier.CreatedBy       = SessionManger.LoggedInUser(Session);
                            aBuyPartsFromSupplier.CreatedDateTime = DateTime.Now;
                            aBuyPartsFromSupplier.EditedBy        = null;
                            aBuyPartsFromSupplier.EditedDateTime  = null;


                            unitOfWork.BuyPartsFromSupplierRepository.Insert(aBuyPartsFromSupplier);
                            unitOfWork.Save();
                        }

                        if (otherExpense != null)
                        {
                            foreach (VM_BuyPartsFromSupplier othersExpenses in otherExpense)
                            {
                                aBuyPartsFromSupplier.RegistrationNo = registrationNo;
                                aBuyPartsFromSupplier.BuyDate        = buyDate;
                                aBuyPartsFromSupplier.PartsId        = null;
                                aBuyPartsFromSupplier.SupplierId     = null;
                                aBuyPartsFromSupplier.Quantity       = null;
                                aBuyPartsFromSupplier.UnitPrice      = null;
                                aBuyPartsFromSupplier.Other          = othersExpenses.Other;
                                aBuyPartsFromSupplier.Price          = othersExpenses.Price;
                                aBuyPartsFromSupplier.StoreId        = null;
                                aBuyPartsFromSupplier.WorkShopId     =
                                    Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                                aBuyPartsFromSupplier.CreatedBy       = SessionManger.LoggedInUser(Session);
                                aBuyPartsFromSupplier.CreatedDateTime = DateTime.Now;
                                aBuyPartsFromSupplier.EditedBy        = null;
                                aBuyPartsFromSupplier.EditedDateTime  = null;

                                unitOfWork.BuyPartsFromSupplierRepository.Insert(aBuyPartsFromSupplier);
                                unitOfWork.Save();
                            }
                        }
                    }

                    return(Json(new { success = true, successMessage = " Added Successfully!" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { success = false, errorMessage = "Model is not valid" }, JsonRequestBehavior.AllowGet));
            }
        }
        //[ValidateAntiForgeryToken]
        //public async Task<ActionResult> Register(RegisterViewModel model)
        //{
        //    if (ModelState.IsValid)
        //    {
        //        var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
        //        var result = await UserManager.CreateAsync(user, model.Password);
        //        if (result.Succeeded)
        //        {
        //            await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

        //            // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
        //            // Send an email with this link
        //            // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
        //            // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
        //            // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

        //            return RedirectToAction("Index", "Home");
        //        }
        //        AddErrors(result);
        //    }

        //    // If we got this far, something failed, redisplay form
        //    return View(model);
        //}


        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var results = await UserManager.FindByNameAsync(model.UserName);

                if (results != null)
                {
                    return(Json(new { success = false, errorMessage = "This User Name already exists" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    // Create User
                    var user = new ApplicationUser()
                    {
                        UserName = model.UserName, Email = model.Email, PhoneNumber = model.PhoneNumber
                    };
                    var result = await UserManager.CreateAsync(user, model.Password);

                    HanifWorkShop_DBEntity AgencyCal = new HanifWorkShop_DBEntity();
                    AspNetUser             anu       = new AspNetUser();

                    //AspNetUser userId = RestaurantCal.AspNetRoles.Select(a => a.Name == model.UserName).FirstOrDefault();
                    AspNetUser searchUser = AgencyCal.AspNetUsers.Where(a => a.UserName == model.UserName).FirstOrDefault();
                    decimal    workShopId = SessionManger.WorkShopOfLoggedInUser(Session);
                    if (result.Succeeded)
                    {
                        using (HanifWorkShop_DBEntity rc = new HanifWorkShop_DBEntity())
                        {
                            try
                            {
                                tblWorkShopUser AgencyUser = new tblWorkShopUser();


                                AgencyUser.UserId          = searchUser.Id;
                                AgencyUser.workShop_id     = workShopId;
                                AgencyUser.WorkShopId      = Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                                AgencyUser.CreatedBy       = SessionManger.LoggedInUser(Session);
                                AgencyUser.CreatedDateTime = DateTime.Now;
                                AgencyUser.EditedBy        = null;
                                AgencyUser.EditedDateTime  = null;
                                // RestaurantUser.is_admin = 0;
                                //RestaurantUser.is_loggedIn = null;
                                //RestaurantUser.last_logged_time = null;
                                //RestaurantUser.approve_by = null;
                                //RestaurantUser.approve_date = null;
                                rc.tblWorkShopUsers.Add(AgencyUser);
                                rc.SaveChanges();

                                return(Json(new { success = true, successMessage = "User has created Successfully." }, JsonRequestBehavior.AllowGet));
                            }
                            catch (Exception ex)
                            {
                                return(Json(new { success = false, errorMessage = ex }, JsonRequestBehavior.AllowGet));
                            }
                        }
                    }
                    else
                    {
                        return(Json(new { success = false, errorMessage = "This Email has already taken." }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            else
            {
                return(Json(new { success = false, errorMessage = "Model is not Valid." }, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult ViewPdfReportForSearchResult(int routeId)
        {
            try
            {
                List <DAL.ViewModel.VM_BusInformation> busInfoList = unitOfWork.CustomRepository.sp_BusInformationListForABusRoute((routeId));
                var newBusInfoList = new List <DAL.ViewModel.VM_BusInformation>();
                foreach (var busInfo in busInfoList)
                {
                    DAL.ViewModel.VM_BusInformation newBusInfo = new DAL.ViewModel.VM_BusInformation();
                    newBusInfo.RegistrationNo = busInfo.RegistrationNo;
                    newBusInfo.ModelNo        = busInfo.ModelNo;
                    newBusInfo.ChassisNo      = busInfo.ChassisNo;
                    newBusInfoList.Add(newBusInfo);
                }
                int    workShopId      = Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                string workShopName    = unitOfWork.WorkShopInformationRepository.GetByID(workShopId).Name;
                string workShopAddress = unitOfWork.WorkShopInformationRepository.GetByID(workShopId).Address;
                string routerName      = unitOfWork.RouteRepository.GetByID(routeId).RouteName;

                LocalReport localReport = new LocalReport();
                localReport.ReportPath = Server.MapPath("~/Reports/BusInfornationListForSpecificBusRouteReport.rdlc");
                localReport.SetParameters(new ReportParameter("RouterName", routerName.ToString()));
                localReport.SetParameters(new ReportParameter("WorkShopName", workShopName));
                localReport.SetParameters(new ReportParameter("WorkShopAddress", workShopAddress));
                ReportDataSource reportDataSource = new ReportDataSource("BusInfornationListForSpecificBusRouteDataSet", newBusInfoList);

                localReport.DataSources.Add(reportDataSource);
                string reportType = "pdf";
                string mimeType;
                string encoding;
                string fileNameExtension;
                //The DeviceInfo settings should be changed based on the reportType
                //http://msdn.microsoft.com/en-us/library/ms155397.aspx
                string deviceInfo =
                    "<DeviceInfo>" +
                    "  <OutputFormat>PDF</OutputFormat>" +
                    "  <PageWidth>8.5in</PageWidth>" +
                    "  <PageHeight>11in</PageHeight>" +
                    "  <MarginTop>0.5in</MarginTop>" +
                    "  <MarginLeft>0in</MarginLeft>" +
                    "  <MarginRight>0in</MarginRight>" +
                    "  <MarginBottom>0.1in</MarginBottom>" +
                    "</DeviceInfo>";

                Warning[] warnings;
                string[]  streams;
                byte[]    renderedBytes;

                //Render the report
                renderedBytes = localReport.Render(
                    reportType,
                    deviceInfo,
                    out mimeType,
                    out encoding,
                    out fileNameExtension,
                    out streams,
                    out warnings);
                return(File(renderedBytes, mimeType));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #18
0
        public ActionResult ViewPdfReportForSearchResult(string registrationNo, string fromDate, string toDate)
        {
            try
            {
                List <DAL.ViewModel.VM_CostForBusRegistrationNo> totalCostInfoList = unitOfWork.CustomRepository.sp_totalCostHistoryFromDateToDateForBusRegistrationNoFullFinal(registrationNo, Convert.ToDateTime(fromDate), Convert.ToDateTime(toDate));
                var newTotalCostInfoList = new List <DAL.ViewModel.VM_CostForBusRegistrationNo>();
                foreach (var totalCostInfo in totalCostInfoList)
                {
                    DAL.ViewModel.VM_CostForBusRegistrationNo newtotalCostInfo = new DAL.ViewModel.VM_CostForBusRegistrationNo();
                    newtotalCostInfo.CompanyName = totalCostInfo.CompanyName;
                    newtotalCostInfo.PartsName   = totalCostInfo.PartsName;
                    newtotalCostInfo.Other       = totalCostInfo.Other;
                    newtotalCostInfo.Quantity    = totalCostInfo.Quantity;
                    newtotalCostInfo.UnitPrice   = totalCostInfo.UnitPrice;
                    newtotalCostInfo.Price       = totalCostInfo.Price;
                    newtotalCostInfo.StoreName   = totalCostInfo.StoreName;
                    newTotalCostInfoList.Add(totalCostInfo);
                }
                int    workShopId      = Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                string workShopName    = unitOfWork.WorkShopInformationRepository.GetByID(workShopId).Name;
                string workShopAddress = unitOfWork.WorkShopInformationRepository.GetByID(workShopId).Address;



                LocalReport localReport = new LocalReport();
                localReport.ReportPath = Server.MapPath("~/Reports/TotalCostHistoryFromDateToDateForABusRegistrationNoReport.rdlc");
                localReport.SetParameters(new ReportParameter("RegistrationNo", registrationNo));
                localReport.SetParameters(new ReportParameter("FromDate", fromDate.ToString()));
                localReport.SetParameters(new ReportParameter("ToDate", toDate.ToString()));
                localReport.SetParameters(new ReportParameter("WorkShopName", workShopName));
                localReport.SetParameters(new ReportParameter("WorkShopAddress", workShopAddress));
                ReportDataSource reportDataSource = new ReportDataSource("TotalCostHistoryFromDateToDateForABusRegistrationNoDataSet", newTotalCostInfoList);

                localReport.DataSources.Add(reportDataSource);
                string reportType = "pdf";
                string mimeType;
                string encoding;
                string fileNameExtension;
                //The DeviceInfo settings should be changed based on the reportType
                //http://msdn.microsoft.com/en-us/library/ms155397.aspx
                string deviceInfo =
                    "<DeviceInfo>" +
                    "  <OutputFormat>PDF</OutputFormat>" +
                    "  <PageWidth>8.5in</PageWidth>" +
                    "  <PageHeight>11in</PageHeight>" +
                    "  <MarginTop>0.5in</MarginTop>" +
                    "  <MarginLeft>0in</MarginLeft>" +
                    "  <MarginRight>0in</MarginRight>" +
                    "  <MarginBottom>0.5in</MarginBottom>" +
                    "</DeviceInfo>";

                Warning[] warnings;
                string[]  streams;
                byte[]    renderedBytes;

                //Render the report
                renderedBytes = localReport.Render(
                    reportType,
                    deviceInfo,
                    out mimeType,
                    out encoding,
                    out fileNameExtension,
                    out streams,
                    out warnings);
                return(File(renderedBytes, mimeType));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #19
0
        public ActionResult AddPartsInBusRegistrationNoFromStore(string registrationNo, DateTime buyDate, int storeId, List <Vm_PartsTransfetToBusRegistrationNoFromStore> partsList)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    foreach (Vm_PartsTransfetToBusRegistrationNoFromStore addPartFromStore in partsList)
                    {
                        tblBuyPartsFromSupplier addPartsFromStore = new tblBuyPartsFromSupplier();

                        addPartsFromStore.RegistrationNo = registrationNo;
                        addPartsFromStore.BuyDate        = buyDate;
                        addPartsFromStore.PartsId        = addPartFromStore.PartsId;
                        addPartsFromStore.SupplierId     = null;
                        addPartsFromStore.Quantity       = addPartFromStore.Quantity;
                        addPartsFromStore.UnitPrice      = addPartFromStore.UnitPrice;
                        addPartsFromStore.Other          = null;
                        addPartsFromStore.StoreId        = storeId;
                        addPartsFromStore.Price          = addPartFromStore.Quantity * addPartFromStore.UnitPrice;
                        addPartsFromStore.WorkShopId     =
                            Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                        addPartsFromStore.CreatedBy       = SessionManger.LoggedInUser(Session);
                        addPartsFromStore.CreatedDateTime = DateTime.Now;
                        addPartsFromStore.EditedBy        = null;
                        addPartsFromStore.EditedDateTime  = null;

                        unitOfWork.BuyPartsFromSupplierRepository.Insert(addPartsFromStore);
                        unitOfWork.Save();


                        tblPartsTransfer aPartsTransfer = new tblPartsTransfer();

                        aPartsTransfer.StoreId    = storeId;
                        aPartsTransfer.Date       = buyDate;
                        aPartsTransfer.PartsId    = addPartFromStore.PartsId;
                        aPartsTransfer.Quantity   = addPartFromStore.Quantity;
                        aPartsTransfer.UnitPrice  = addPartFromStore.UnitPrice;
                        aPartsTransfer.Price      = addPartFromStore.Quantity * addPartFromStore.UnitPrice;
                        aPartsTransfer.isIn       = false;
                        aPartsTransfer.isOut      = true;
                        aPartsTransfer.WorkShopId =
                            Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                        aPartsTransfer.CreatedBy       = SessionManger.LoggedInUser(Session);
                        aPartsTransfer.CreatedDateTime = DateTime.Now;
                        aPartsTransfer.EditedBy        = null;
                        aPartsTransfer.EditedDateTime  = null;


                        unitOfWork.PartsTransferRepository.Insert(aPartsTransfer);
                        unitOfWork.Save();
                    }



                    return(Json(new { success = true, successMessage = " Added Successfully!" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { success = false, errorMessage = "Model is not valid" }, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #20
0
        public JsonResult GenerateReportForSearchResult(string registrationNo, string fromDate, string toDate)
        {
            try
            {
                List <DAL.ViewModel.VM_CostForBusRegistrationNo> totalCostInfoList = unitOfWork.CustomRepository.sp_totalCostHistoryFromDateToDateForBusRegistrationNoFullFinal(registrationNo, Convert.ToDateTime(fromDate), Convert.ToDateTime(toDate));
                double totalAmount          = 0;
                var    newTotalCostInfoList = new List <DAL.ViewModel.VM_CostForBusRegistrationNo>();
                foreach (var totalCostInfo in totalCostInfoList)
                {
                    DAL.ViewModel.VM_CostForBusRegistrationNo newtotalCostInfo = new DAL.ViewModel.VM_CostForBusRegistrationNo();
                    newtotalCostInfo.CompanyName = totalCostInfo.CompanyName;
                    newtotalCostInfo.PartsName   = totalCostInfo.PartsName;
                    newtotalCostInfo.Other       = totalCostInfo.Other;
                    newtotalCostInfo.Quantity    = totalCostInfo.Quantity;
                    newtotalCostInfo.UnitPrice   = totalCostInfo.UnitPrice;
                    newtotalCostInfo.Price       = totalCostInfo.Price;
                    newtotalCostInfo.StoreName   = totalCostInfo.StoreName;
                    newTotalCostInfoList.Add(totalCostInfo);
                }

                totalAmount = totalCostInfoList.Select(s => s.Price).Sum();
                int    workShopId      = Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                string workShopName    = unitOfWork.WorkShopInformationRepository.GetByID(workShopId).Name;
                string workShopAddress = unitOfWork.WorkShopInformationRepository.GetByID(workShopId).Address;



                LocalReport localReport = new LocalReport();
                localReport.ReportPath = Server.MapPath("~/Reports/TotalCostHistoryFromDateToDateForABusRegistrationNoReport.rdlc");
                localReport.SetParameters(new ReportParameter("RegistrationNo", registrationNo));
                localReport.SetParameters(new ReportParameter("FromDate", fromDate.ToString()));
                localReport.SetParameters(new ReportParameter("ToDate", toDate.ToString()));
                localReport.SetParameters(new ReportParameter("WorkShopName", workShopName));
                localReport.SetParameters(new ReportParameter("WorkShopAddress", workShopAddress));
                ReportDataSource reportDataSource = new ReportDataSource("TotalCostHistoryFromDateToDateForABusRegistrationNoDataSet", newTotalCostInfoList);

                localReport.DataSources.Add(reportDataSource);
                string reportType = "pdf";
                string mimeType;
                string encoding;
                string fileNameExtension;
                //The DeviceInfo settings should be changed based on the reportType
                //http://msdn.microsoft.com/en-us/library/ms155397.aspx
                string deviceInfo =
                    "<DeviceInfo>" +
                    "  <OutputFormat>PDF</OutputFormat>" +
                    "  <PageWidth>8.5in</PageWidth>" +
                    "  <PageHeight>11in</PageHeight>" +
                    "  <MarginTop>0.5in</MarginTop>" +
                    "  <MarginLeft>0in</MarginLeft>" +
                    "  <MarginRight>0in</MarginRight>" +
                    "  <MarginBottom>0.5in</MarginBottom>" +
                    "</DeviceInfo>";
                Warning[] warnings;
                string[]  streams;
                byte[]    renderedBytes;
                //Render the report
                renderedBytes = localReport.Render(
                    reportType,
                    deviceInfo,
                    out mimeType,
                    out encoding,
                    out fileNameExtension,
                    out streams,
                    out warnings);
                var path   = System.IO.Path.Combine(Server.MapPath("~/pdfReport"));
                var saveAs = string.Format("{0}.pdf", Path.Combine(path, "myfilename"));

                var idx = 0;
                while (System.IO.File.Exists(saveAs))
                {
                    idx++;
                    saveAs = string.Format("{0}.{1}.pdf", Path.Combine(path, "myfilename"), idx);
                }
                Session["report"] = saveAs;
                using (var stream = new FileStream(saveAs, FileMode.Create, FileAccess.Write))
                {
                    stream.Write(renderedBytes, 0, renderedBytes.Length);
                    stream.Close();
                }
                localReport.Dispose();
                return(Json(new { success = true, successMessage = "Report generated successfully.", result = totalCostInfoList, TotalAmount = totalAmount }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult GenerateReportForSearchResult(int?id)
        {
            try
            {
                double totalAmount = 0;
                var    storeInfo   = unitOfWork.StoreRepository.Get().Where(s => s.StoreId == id).FirstOrDefault();

                var partsId = unitOfWork.PartsTransferRepository.Get().Where(a => a.StoreId == storeInfo.StoreId).DistinctBy(a => a.tblPartsInfo.PartsId).ToList();

                var partsList = new List <Vm_PartsTransfetToBusRegistrationNoFromStore>();
                foreach (var aParts in partsId)
                {
                    if (aParts != null)
                    {
                        Vm_PartsTransfetToBusRegistrationNoFromStore newParts = new Vm_PartsTransfetToBusRegistrationNoFromStore();
                        var partsInfo = unitOfWork.PartsInfoRepository.GetByID(aParts.PartsId);

                        if (partsInfo != null)
                        {
                            int partsIn  = (int)unitOfWork.PartsTransferRepository.Get().Where(x => x.isIn == true && x.PartsId == partsInfo.PartsId).Select(x => x.Quantity).Sum();
                            int partsOut = (int)unitOfWork.PartsTransferRepository.Get().Where(x => x.isOut == true && x.PartsId == partsInfo.PartsId).Select(x => x.Quantity).Sum();

                            int getProductAvilableQty = partsIn - partsOut;



                            if (getProductAvilableQty > 0)
                            {
                                newParts.PartsId          = partsInfo.PartsId;
                                newParts.PartsName        = partsInfo.PartsName;
                                newParts.UnitPrice        = Convert.ToInt32(partsInfo.BasePrice);
                                newParts.AvailableQuatity = getProductAvilableQty;
                                newParts.Price            = newParts.AvailableQuatity * newParts.UnitPrice;
                                totalAmount += newParts.Price;
                                partsList.Add(newParts);
                            }
                        }
                    }
                }

                int    workShopId      = Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                string workShopName    = unitOfWork.WorkShopInformationRepository.GetByID(workShopId).Name;
                string workShopAddress = unitOfWork.WorkShopInformationRepository.GetByID(workShopId).Address;
                string storeName       = unitOfWork.StoreRepository.GetByID(id).StoreName;



                LocalReport localReport = new LocalReport();
                localReport.ReportPath = Server.MapPath("~/Reports/PartsStatusInStoreReport.rdlc");
                localReport.SetParameters(new ReportParameter("StoreName", storeName));
                localReport.SetParameters(new ReportParameter("WorkShopName", workShopName));
                localReport.SetParameters(new ReportParameter("WorkShopAddress", workShopAddress));
                ReportDataSource reportDataSource = new ReportDataSource("PartsStatusInStoreDataSet", partsList);

                localReport.DataSources.Add(reportDataSource);
                string reportType = "pdf";
                string mimeType;
                string encoding;
                string fileNameExtension;
                //The DeviceInfo settings should be changed based on the reportType
                //http://msdn.microsoft.com/en-us/library/ms155397.aspx
                string deviceInfo =
                    "<DeviceInfo>" +
                    "  <OutputFormat>PDF</OutputFormat>" +
                    "  <PageWidth>8.5in</PageWidth>" +
                    "  <PageHeight>11in</PageHeight>" +
                    "  <MarginTop>0.5in</MarginTop>" +
                    "  <MarginLeft>0in</MarginLeft>" +
                    "  <MarginRight>0in</MarginRight>" +
                    "  <MarginBottom>0.5in</MarginBottom>" +
                    "</DeviceInfo>";
                Warning[] warnings;
                string[]  streams;
                byte[]    renderedBytes;
                //Render the report
                renderedBytes = localReport.Render(
                    reportType,
                    deviceInfo,
                    out mimeType,
                    out encoding,
                    out fileNameExtension,
                    out streams,
                    out warnings);
                var path   = System.IO.Path.Combine(Server.MapPath("~/pdfReport"));
                var saveAs = string.Format("{0}.pdf", Path.Combine(path, "myfilename"));

                var idx = 0;
                while (System.IO.File.Exists(saveAs))
                {
                    idx++;
                    saveAs = string.Format("{0}.{1}.pdf", Path.Combine(path, "myfilename"), idx);
                }
                Session["report"] = saveAs;
                using (var stream = new FileStream(saveAs, FileMode.Create, FileAccess.Write))
                {
                    stream.Write(renderedBytes, 0, renderedBytes.Length);
                    stream.Close();
                }
                localReport.Dispose();
                return(Json(new { success = true, successMessage = "Report generated successfully.", result = partsList, TotalAmount = totalAmount }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult SaveEmployeeInformation(HttpPostedFileBase file, HttpPostedFileBase nidFile, HttpPostedFileBase drivingLicenseFile, VM_EmployeeInformation aEmployee)
        {
            //string emptyEmail = "undefined";
            var EmailExist = unitOfWork.EmployeeInformationRepository.Get()
                             .Where(a => a.EmployeeEmail == aEmployee.EmployeeEmail && a.EmployeeEmail != "undefined" && a.EmployeeEmail != "").ToList();


            if (ModelState.IsValid)
            {
                try
                {
                    if (!EmailExist.Any())
                    {
                        string path = "";
                        if (file != null)
                        {
                            string pic = System.IO.Path.GetFileName(file.FileName);
                            path = System.IO.Path.Combine(
                                Server.MapPath("~/Image"), pic);
                            // file is uploaded
                            file.SaveAs(path);

                            if (nidFile != null)
                            {
                                string picNid = System.IO.Path.GetFileName(nidFile.FileName);
                                path = System.IO.Path.Combine(
                                    Server.MapPath("~/Image"), picNid);
                                // file is uploaded
                                nidFile.SaveAs(path);

                                if (drivingLicenseFile != null)
                                {
                                    string picDrivingLicense = System.IO.Path.GetFileName(drivingLicenseFile.FileName);
                                    path = System.IO.Path.Combine(
                                        Server.MapPath("~/Image"), picDrivingLicense);
                                    // file is uploaded
                                    drivingLicenseFile.SaveAs(path);

                                    tblEmployeeInformation employee = new tblEmployeeInformation();
                                    employee.EmployeeName        = aEmployee.EmployeeName;
                                    employee.EmployeeAddress     = aEmployee.EmployeeAddress;
                                    employee.ContactNumber       = aEmployee.ContactNumber;
                                    employee.EmployeeNid         = aEmployee.EmployeeNid;
                                    employee.EmployeeNidImage    = "/Image/" + picNid;
                                    employee.EmployeeEmail       = aEmployee.EmployeeEmail;
                                    employee.EmployeeImage       = "/Image/" + pic;
                                    employee.DesignationId       = aEmployee.DesignationId;
                                    employee.DrivingLicenseImage = "/Image/" + picDrivingLicense;
                                    employee.Salary     = aEmployee.Salary;
                                    employee.RouteId    = aEmployee.RouteId;
                                    employee.WorkShopId =
                                        Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                                    employee.CreatedBy       = SessionManger.LoggedInUser(Session);
                                    employee.CreatedDateTime = DateTime.Now;
                                    employee.EditedBy        = null;
                                    employee.EditedDateTime  = null;

                                    unitOfWork.EmployeeInformationRepository.Insert(employee);
                                    unitOfWork.Save();
                                }

                                else
                                {
                                    tblEmployeeInformation employee = new tblEmployeeInformation();
                                    employee.EmployeeName        = aEmployee.EmployeeName;
                                    employee.EmployeeAddress     = aEmployee.EmployeeAddress;
                                    employee.ContactNumber       = aEmployee.ContactNumber;
                                    employee.EmployeeNid         = aEmployee.EmployeeNid;
                                    employee.EmployeeNidImage    = "/Image/" + picNid;
                                    employee.EmployeeEmail       = aEmployee.EmployeeEmail;
                                    employee.EmployeeImage       = "/Image/" + pic;
                                    employee.DesignationId       = aEmployee.DesignationId;
                                    employee.DrivingLicenseImage = aEmployee.DrivingLicenseImage;
                                    employee.Salary     = aEmployee.Salary;
                                    employee.RouteId    = aEmployee.RouteId;
                                    employee.WorkShopId =
                                        Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                                    employee.CreatedBy       = SessionManger.LoggedInUser(Session);
                                    employee.CreatedDateTime = DateTime.Now;
                                    employee.EditedBy        = null;
                                    employee.EditedDateTime  = null;

                                    unitOfWork.EmployeeInformationRepository.Insert(employee);
                                    unitOfWork.Save();
                                }
                            }
                            else
                            {
                                if (drivingLicenseFile != null)
                                {
                                    string picDrivingLicense = System.IO.Path.GetFileName(drivingLicenseFile.FileName);
                                    path = System.IO.Path.Combine(
                                        Server.MapPath("~/Image"), picDrivingLicense);
                                    // file is uploaded
                                    drivingLicenseFile.SaveAs(path);


                                    tblEmployeeInformation employee = new tblEmployeeInformation();
                                    employee.EmployeeName        = aEmployee.EmployeeName;
                                    employee.EmployeeAddress     = aEmployee.EmployeeAddress;
                                    employee.ContactNumber       = aEmployee.ContactNumber;
                                    employee.EmployeeNid         = aEmployee.EmployeeNid;
                                    employee.EmployeeNidImage    = aEmployee.EmployeeNidImage;
                                    employee.EmployeeEmail       = aEmployee.EmployeeEmail;
                                    employee.EmployeeImage       = "/Image/" + pic;
                                    employee.DesignationId       = aEmployee.DesignationId;
                                    employee.DrivingLicenseImage = "/Image/" + picDrivingLicense;
                                    employee.Salary     = aEmployee.Salary;
                                    employee.RouteId    = aEmployee.RouteId;
                                    employee.WorkShopId =
                                        Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                                    employee.CreatedBy       = SessionManger.LoggedInUser(Session);
                                    employee.CreatedDateTime = DateTime.Now;
                                    employee.EditedBy        = null;
                                    employee.EditedDateTime  = null;

                                    unitOfWork.EmployeeInformationRepository.Insert(employee);
                                    unitOfWork.Save();
                                }
                                else
                                {
                                    tblEmployeeInformation employee = new tblEmployeeInformation();
                                    employee.EmployeeName        = aEmployee.EmployeeName;
                                    employee.EmployeeAddress     = aEmployee.EmployeeAddress;
                                    employee.ContactNumber       = aEmployee.ContactNumber;
                                    employee.EmployeeNid         = aEmployee.EmployeeNid;
                                    employee.EmployeeNidImage    = aEmployee.EmployeeNidImage;
                                    employee.EmployeeEmail       = aEmployee.EmployeeEmail;
                                    employee.EmployeeImage       = "/Image/" + pic;
                                    employee.DesignationId       = aEmployee.DesignationId;
                                    employee.DrivingLicenseImage = aEmployee.DrivingLicenseImage;
                                    employee.Salary     = aEmployee.Salary;
                                    employee.RouteId    = aEmployee.RouteId;
                                    employee.WorkShopId =
                                        Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                                    employee.CreatedBy       = SessionManger.LoggedInUser(Session);
                                    employee.CreatedDateTime = DateTime.Now;
                                    employee.EditedBy        = null;
                                    employee.EditedDateTime  = null;

                                    unitOfWork.EmployeeInformationRepository.Insert(employee);
                                    unitOfWork.Save();
                                }
                            }
                        }
                        else
                        {
                            if (nidFile != null)
                            {
                                string picNid = System.IO.Path.GetFileName(nidFile.FileName);
                                path = System.IO.Path.Combine(
                                    Server.MapPath("~/Image"), picNid);
                                // file is uploaded
                                nidFile.SaveAs(path);

                                if (drivingLicenseFile != null)
                                {
                                    string picDrivingLicense = System.IO.Path.GetFileName(drivingLicenseFile.FileName);
                                    path = System.IO.Path.Combine(
                                        Server.MapPath("~/Image"), picDrivingLicense);
                                    // file is uploaded
                                    drivingLicenseFile.SaveAs(path);


                                    tblEmployeeInformation employee = new tblEmployeeInformation();
                                    employee.EmployeeName        = aEmployee.EmployeeName;
                                    employee.EmployeeAddress     = aEmployee.EmployeeAddress;
                                    employee.ContactNumber       = aEmployee.ContactNumber;
                                    employee.EmployeeNid         = aEmployee.EmployeeNid;
                                    employee.EmployeeNidImage    = "/Image/" + picNid;
                                    employee.EmployeeEmail       = aEmployee.EmployeeEmail;
                                    employee.EmployeeImage       = aEmployee.EmployeeImage;
                                    employee.DesignationId       = aEmployee.DesignationId;
                                    employee.DrivingLicenseImage = "/Image/" + picDrivingLicense;
                                    employee.Salary     = aEmployee.Salary;
                                    employee.RouteId    = aEmployee.RouteId;
                                    employee.WorkShopId =
                                        Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                                    employee.CreatedBy       = SessionManger.LoggedInUser(Session);
                                    employee.CreatedDateTime = DateTime.Now;
                                    employee.EditedBy        = null;
                                    employee.EditedDateTime  = null;
                                    unitOfWork.EmployeeInformationRepository.Insert(employee);
                                    unitOfWork.Save();
                                }
                                else
                                {
                                    tblEmployeeInformation employee = new tblEmployeeInformation();
                                    employee.EmployeeName        = aEmployee.EmployeeName;
                                    employee.EmployeeAddress     = aEmployee.EmployeeAddress;
                                    employee.ContactNumber       = aEmployee.ContactNumber;
                                    employee.EmployeeNid         = aEmployee.EmployeeNid;
                                    employee.EmployeeNidImage    = "/Image/" + picNid;
                                    employee.EmployeeEmail       = aEmployee.EmployeeEmail;
                                    employee.EmployeeImage       = aEmployee.EmployeeImage;
                                    employee.DesignationId       = aEmployee.DesignationId;
                                    employee.DrivingLicenseImage = aEmployee.DrivingLicenseImage;
                                    employee.Salary     = aEmployee.Salary;
                                    employee.RouteId    = aEmployee.RouteId;
                                    employee.WorkShopId =
                                        Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                                    employee.CreatedBy       = SessionManger.LoggedInUser(Session);
                                    employee.CreatedDateTime = DateTime.Now;
                                    employee.EditedBy        = null;
                                    employee.EditedDateTime  = null;
                                    unitOfWork.EmployeeInformationRepository.Insert(employee);
                                    unitOfWork.Save();
                                }
                            }
                            else
                            {
                                if (drivingLicenseFile != null)
                                {
                                    string picDrivingLicense = System.IO.Path.GetFileName(drivingLicenseFile.FileName);
                                    path = System.IO.Path.Combine(
                                        Server.MapPath("~/Image"), picDrivingLicense);
                                    // file is uploaded
                                    drivingLicenseFile.SaveAs(path);


                                    tblEmployeeInformation employee = new tblEmployeeInformation();
                                    employee.EmployeeName        = aEmployee.EmployeeName;
                                    employee.EmployeeAddress     = aEmployee.EmployeeAddress;
                                    employee.ContactNumber       = aEmployee.ContactNumber;
                                    employee.EmployeeNid         = aEmployee.EmployeeNid;
                                    employee.EmployeeNidImage    = aEmployee.EmployeeNidImage;
                                    employee.EmployeeEmail       = aEmployee.EmployeeEmail;
                                    employee.EmployeeImage       = aEmployee.EmployeeImage;
                                    employee.DesignationId       = aEmployee.DesignationId;
                                    employee.DrivingLicenseImage = "/Image/" + picDrivingLicense;
                                    employee.Salary     = aEmployee.Salary;
                                    employee.RouteId    = aEmployee.RouteId;
                                    employee.WorkShopId =
                                        Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                                    employee.CreatedBy       = SessionManger.LoggedInUser(Session);
                                    employee.CreatedDateTime = DateTime.Now;
                                    employee.EditedBy        = null;
                                    employee.EditedDateTime  = null;
                                    unitOfWork.EmployeeInformationRepository.Insert(employee);
                                    unitOfWork.Save();
                                }
                                else
                                {
                                    tblEmployeeInformation employee = new tblEmployeeInformation();
                                    employee.EmployeeName        = aEmployee.EmployeeName;
                                    employee.EmployeeAddress     = aEmployee.EmployeeAddress;
                                    employee.ContactNumber       = aEmployee.ContactNumber;
                                    employee.EmployeeNid         = aEmployee.EmployeeNid;
                                    employee.EmployeeNidImage    = aEmployee.EmployeeNidImage;
                                    employee.EmployeeEmail       = aEmployee.EmployeeEmail;
                                    employee.EmployeeImage       = aEmployee.EmployeeImage;
                                    employee.DesignationId       = aEmployee.DesignationId;
                                    employee.DrivingLicenseImage = aEmployee.DrivingLicenseImage;
                                    employee.Salary     = aEmployee.Salary;
                                    employee.RouteId    = aEmployee.RouteId;
                                    employee.WorkShopId =
                                        Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                                    employee.CreatedBy       = SessionManger.LoggedInUser(Session);
                                    employee.CreatedDateTime = DateTime.Now;
                                    employee.EditedBy        = null;
                                    employee.EditedDateTime  = null;
                                    unitOfWork.EmployeeInformationRepository.Insert(employee);
                                    unitOfWork.Save();
                                }
                            }
                        }
                        return(Json(new { success = true, successMessage = "Employee Information Added Successfully" }));
                    }
                    else
                    {
                        return(Json(new { success = false, errorMessage = "The email already exist" }, JsonRequestBehavior.AllowGet));
                    }
                }
                catch (Exception ex)
                {
                    return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { success = false, errorMessage = "Please Fill Up all required field." }, JsonRequestBehavior.AllowGet));
            }
        }