Exemple #1
0
        public ActionResult EditBlock(int id)
        {
            var block = new Block();

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

                var myViewObj = new BlockServices().GetBlock(id);

                if (myViewObj == null || myViewObj.BlockId < 1)
                {
                    block.Error     = "Block  Information could not be retrieved.";
                    block.ErrorCode = -1;
                    return(Json(block, JsonRequestBehavior.AllowGet));
                }
                Session["_block"]   = myViewObj;
                myViewObj.ErrorCode = myViewObj.BlockId;
                return(Json(myViewObj, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                //ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                block.Error     = "An unknown error was Block  Information could not be retrieved.";
                block.ErrorCode = -1;
                return(Json(block, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #2
0
        public ActionResult DeleteBlock(int id)
        {
            var block = new Block();

            try
            {
                if (id < 1)
                {
                    block.Error     = "Invalid Selection";
                    block.ErrorCode = 0;
                    return(Json(block, JsonRequestBehavior.AllowGet));
                }
                if (new BlockServices().DeleteBlockCheckReferences(id))
                {
                    block.Error     = "Block  Information was successfully deleted.";
                    block.ErrorCode = 1;
                    return(Json(block, JsonRequestBehavior.AllowGet));
                }

                block.Error     = "Process Failed! Please try again later";
                block.ErrorCode = 0;
                return(Json(block, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                //ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                block.Error     = "An unknown error was encountered. Please contact the Administrator or try again later.";
                block.ErrorCode = 0;
                return(Json(block, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #3
0
        public ActionResult AddBlock(Block block)
        {
            ModelState.Clear();
            ViewBag.LoadStatus = "0";
            try
            {
                if (!ModelState.IsValid)
                {
                    block.Error     = "Please supply all required fields and try again";
                    block.ErrorCode = -1;
                    return(Json(block, JsonRequestBehavior.AllowGet));
                }

                var wx = ValidateControl(block);

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

                var k = new BlockServices().AddBlockCheckDuplicate(block);
                if (k < 1)
                {
                    if (k == -3)
                    {
                        block.Error     = "Block  already exists";
                        block.ErrorCode = -3;
                        return(Json(block, JsonRequestBehavior.AllowGet));
                    }

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

                block.Error     = "Record was added successfully";
                block.ErrorCode = 1;
                block.BlockId   = k;
                return(Json(block, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                //ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                block.Error     = "An unknown error was encountered. Request could not be serviced. Please try again later.";
                block.ErrorCode = 0;
                return(Json(block, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #4
0
        private static GenericValidator ValidateControl(Block model)
        {
            var gVal = new GenericValidator();

            try
            {
                if (string.IsNullOrEmpty(model.Name.Trim()))
                {
                    gVal.Error = "Please enter Block  Name.";
                    gVal.Code  = 0;
                    return(gVal);
                }

                if (model.CompanyId < 1)
                {
                    gVal.Error = "Please select a valid Company.";
                    gVal.Code  = 0;
                    return(gVal);
                }

                if (model.BlockTypeId < 1)
                {
                    gVal.Error = "Please select a valid Block Type.";
                    gVal.Code  = 0;
                    return(gVal);
                }

                if (model.LeaseTypeId < 1)
                {
                    gVal.Error = "Please select a valid Lease Type.";
                    gVal.Code  = 0;
                    return(gVal);
                }

                gVal.Code = 1;
                return(gVal);
            }
            catch (Exception)
            {
                gVal.Error = "Process validation failed. Please supply all required fields and try again.";
                gVal.Code  = 0;
                return(gVal);
            }
        }
Exemple #5
0
        public ActionResult EditBlock(Block block)
        {
            ModelState.Clear();
            ViewBag.LoadStatus = "0";
            try
            {
                if (Session["_block"] == null)
                {
                    block.Error     = "Session has expired";
                    block.ErrorCode = 0;
                    return(Json(block, JsonRequestBehavior.AllowGet));
                }

                var oldBlock = Session["_block"] as Block;

                if (oldBlock == null || oldBlock.BlockId < 1)
                {
                    block.Error     = "Session has expired";
                    block.ErrorCode = 0;
                    return(Json(block, JsonRequestBehavior.AllowGet));
                }

                if (!ModelState.IsValid)
                {
                    block.Error     = "Please supply all required fields and try again";
                    block.ErrorCode = -1;
                    return(Json(block, JsonRequestBehavior.AllowGet));
                }

                var wx = ValidateControl(block);

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

                oldBlock.Name        = block.Name;
                oldBlock.CompanyId   = block.CompanyId;
                oldBlock.LeaseTypeId = block.LeaseTypeId;
                oldBlock.YearOfAward = block.YearOfAward;
                oldBlock.Area        = block.Area;
                oldBlock.BlockTypeId = block.BlockTypeId;

                var k = new BlockServices().UpdateBlockCheckDuplicate(oldBlock);
                if (k < 1)
                {
                    if (k == -3)
                    {
                        block.Error     = "Block  already exists";
                        block.ErrorCode = 0;
                        return(Json(block, JsonRequestBehavior.AllowGet));
                    }

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

                block.Error     = "Block  Information was successfully updated";
                block.ErrorCode = 1;
                return(Json(block, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                //ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                block.Error     = "An unknown error was encountered. Request could not be serviced. Please try again later.";
                block.ErrorCode = 0;
                return(Json(block, JsonRequestBehavior.AllowGet));
            }
        }