public ActionResult EditSector(int id)
        {
            var sector = new Sector();

            try
            {
                if (id < 1)
                {
                    sector.Error     = "Invalid Selection!";
                    sector.ErrorCode = -1;
                    return(Json(sector, JsonRequestBehavior.AllowGet));
                }

                var myViewObj = new SectorServices().GetSector(id);

                if (myViewObj == null || myViewObj.SectorId < 1)
                {
                    sector.Error     = "Sector Information could not be retrieved.";
                    sector.ErrorCode = -1;
                    return(Json(sector, JsonRequestBehavior.AllowGet));
                }
                Session["_sector"]  = myViewObj;
                myViewObj.ErrorCode = myViewObj.SectorId;
                return(Json(myViewObj, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                sector.Error     = "An unknown error was Sector Information could not be retrieved.";
                sector.ErrorCode = -1;
                return(Json(sector, JsonRequestBehavior.AllowGet));
            }
        }
        private List <Sector> GetSectors()
        {
            var sectorList = new SectorServices().GetAllOrderedSectors() ?? new List <Sector>();

            if (!sectorList.Any())
            {
                return(new List <Sector>());
            }

            return(sectorList);
        }
        public ViewResult Sectors()
        {
            var sectorList = new SectorServices().GetAllOrderedSectors() ?? new List <Sector>();

            if (!sectorList.Any())
            {
                ViewBag.Title = "Sector Set Up";
                return(View(sectorList));
            }
            sectorList.Remove(sectorList.Find(m => m.SectorId == (int)OtherNotAvailable.Not_Available));
            ViewBag.Title = "Manage Sectors";
            return(View(sectorList));
        }
        public ActionResult AddSector(Sector sector)
        {
            ModelState.Clear();
            ViewBag.LoadStatus = "0";
            try
            {
                if (!ModelState.IsValid)
                {
                    sector.Error     = "Please supply all required fields and try again";
                    sector.ErrorCode = -1;
                    return(Json(sector, JsonRequestBehavior.AllowGet));
                }

                var wx = ValidateControl(sector);

                if (wx.Code < 1)
                {
                    sector.Error     = wx.Error;
                    sector.ErrorCode = -1;
                    return(Json(sector, JsonRequestBehavior.AllowGet));
                }

                sector.Name = sector.Name;
                var k = new SectorServices().AddSectorCheckDuplicate(sector);
                if (k < 1)
                {
                    if (k == -3)
                    {
                        sector.Error     = "Sector already exists";
                        sector.ErrorCode = -3;
                        return(Json(sector, JsonRequestBehavior.AllowGet));
                    }

                    sector.Error     = "Process Failed! Please contact the Admin or try again later";
                    sector.ErrorCode = 0;
                    return(Json(sector, JsonRequestBehavior.AllowGet));
                }

                sector.Error     = "Record was added successfully";
                sector.ErrorCode = 1;
                sector.SectorId  = k;
                return(Json(sector, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                sector.Error     = "An unknown error was encountered. Request could not be serviced. Please try again later.";
                sector.ErrorCode = 0;
                return(Json(sector, JsonRequestBehavior.AllowGet));
            }
        }
 public HomeController(
     UserManager <ApplicationUser> userManager,
     IHostingEnvironment env,
     IStringLocalizer <HomeController> stringLocalizer,
     IMemoryCache memoryCache,
     IOptions <JsonLocalizationOptions> options,
     CountryServices countryServices,
     SectorServices sectorServices
     )
 {
     _userManager     = userManager;
     _stringLocalizer = stringLocalizer;
     _env             = env;
     _cache           = memoryCache;
     _countryServices = countryServices;
     _sectorServices  = sectorServices;
     var value = options.Value;
 }
        private Project ProcessRecord(DataRowView dv, ref string msg)
        {
            if (dv == null)
            {
                return(null);
            }
            try
            {
                var mInfo = new Project
                {
                    Name = dv.Row["ProjectName"].ToString().Trim()
                };

                var companyName = dv.Row["CompanyName"].ToString().Trim();
                if (string.IsNullOrEmpty(companyName))
                {
                    msg = "Company Name is empty";
                    return(null);
                }
                var compId = new CompanyServices().GetCompanyId(companyName);

                if (compId < 1)
                {
                    msg = "Company information could not be processed.";
                    return(null);
                }

                mInfo.CompanyId = compId;



                var projectType = dv.Row["ProjectType"].ToString().Trim();
                if (string.IsNullOrEmpty(projectType))
                {
                    msg = "project Type is empty";
                    return(null);
                }
                var projectTypeId = new ProjectTypeServices().GetProjectTypeId(projectType);

                if (projectTypeId < 1)
                {
                    msg = "Project Type information could not be processed.";
                    return(null);
                }

                mInfo.ProjectTypeId = projectTypeId;

                var terrain = dv.Row["Terrain"].ToString().Trim();
                if (string.IsNullOrEmpty(terrain))
                {
                    msg = "Terrain is empty";
                    return(null);
                }
                var terrainId = new TerrainServices().GetTerrainId(terrain);

                if (terrainId < 1)
                {
                    msg = "Terrain information could not be processed.";
                    return(null);
                }

                mInfo.TerrainId = terrainId;

                var sector = dv.Row["Sector"].ToString().Trim();
                if (string.IsNullOrEmpty(sector))
                {
                    msg = "Sector is empty";
                    return(null);
                }
                var sectorId = new SectorServices().GetSectorId(sector);

                if (sectorId < 1)
                {
                    msg = "Sector information could not be processed.";
                    return(null);
                }

                mInfo.SectorId = sectorId;

                var duration = dv.Row["Duration(Months)"].ToString().Trim();
                if (string.IsNullOrEmpty(duration))
                {
                    msg = "Project Duration is empty";
                    return(null);
                }

                int outDur;
                var durResult = int.TryParse(duration, out outDur);
                if (!durResult || outDur < 1)
                {
                    msg = "Project Duration is not Valid";
                    return(null);
                }

                mInfo.Duration = outDur;

                double cost;
                var    costStr = double.TryParse(dv.Row["Cost(Million)"].ToString().Trim(), out cost);
                if (!costStr || cost <= 0)
                {
                    msg = "Invalid Project Cost";
                    return(null);
                }

                mInfo.Cost = cost;

                if (!string.IsNullOrEmpty(dv.Row["Description"].ToString().Trim()))
                {
                    mInfo.Description = dv.Row["Description"].ToString().Trim();
                }

                if (!string.IsNullOrEmpty(dv.Row["Objectives"].ToString().Trim()))
                {
                    mInfo.ProjectObjectives = dv.Row["Objectives"].ToString().Trim();
                }

                if (!string.IsNullOrEmpty(dv.Row["CompletionStatus(Completed/UnCompleted)"].ToString().Trim()))
                {
                    var tts = dv.Row["CompletionStatus(Completed/UnCompleted)"].ToString().Trim().ToLower();
                    if (tts == "completed")
                    {
                        mInfo.CompletionStatus = 1;
                    }
                    if (tts == "uncompleted")
                    {
                        mInfo.CompletionStatus = 0;
                    }
                }

                if (!string.IsNullOrEmpty(dv.Row["DateCompleted(yyyy/MM/dd)"].ToString().Trim()))
                {
                    DateTime ddt;
                    var      dtResult = DateTime.TryParse(dv.Row["DateCompleted(yyyy/MM/dd)"].ToString().Trim(), out ddt);

                    if (!dtResult)
                    {
                        msg = "Invalid Project Completion Date";
                        return(null);
                    }

                    mInfo.DateCompleted = ddt;
                }

                return(mInfo);
            }
            catch (Exception ex)
            {
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                return(null);
            }
        }