//Company Object Scope Validation check the entire object for validity...
        private byte CompanyIsValid(Company item, out string errorMessage)
        {   //validate key
            errorMessage = "";
            if (string.IsNullOrEmpty(item.CompanyID))
            {
                errorMessage = "ID Is Required.";
                return(1);
            }
            EntityStates entityState = GetCompanyState(item);

            if (entityState == EntityStates.Added && CompanyExists(item.CompanyID))
            {
                errorMessage = "Item All Ready Exists.";
                return(1);
            }
            //check cached list for duplicates...
            int count = CompanyList.Count(q => q.CompanyID == item.CompanyID);

            if (count > 1)
            {
                errorMessage = "Item All Ready Exists.";
                return(1);
            }
            //validate Description
            if (string.IsNullOrEmpty(item.Name))
            {
                errorMessage = "Name Is Required.";
                return(1);
            }
            //a value of 2 is pending changes...
            //On Commit we will give it a value of 0...
            return(2);
        }
        public void DeleteCompanyCommand()
        {
            try
            {
                int i  = 0;
                int ii = 0;
                for (int j = SelectedCompanyList.Count - 1; j >= 0; j--)
                {
                    Company item = (Company)SelectedCompanyList[j];
                    //get Max Index...
                    i = CompanyList.IndexOf(item);
                    if (i > ii)
                    {
                        ii = i;
                    }
                    Delete(item);
                    CompanyList.Remove(item);
                }

                if (CompanyList != null && CompanyList.Count > 0)
                {
                    //back off one index from the max index...
                    ii = ii - 1;

                    //if they delete the first row...
                    if (ii < 0)
                    {
                        ii = 0;
                    }

                    //make sure it does not exceed the list count...
                    if (ii >= CompanyList.Count())
                    {
                        ii = CompanyList.Count - 1;
                    }

                    SelectedCompany = CompanyList[ii];
                    //we will only enable committ for dirty validated records...
                    if (Dirty == true)
                    {
                        AllowCommit = CommitIsAllowed();
                    }
                    else
                    {
                        AllowCommit = false;
                    }
                }
                else//only one record, deleting will result in no records...
                {
                    SetAsEmptySelection();
                }
            }//we try catch item delete as it may be used in another table as a key...
            //As well we will force a refresh to sqare up the UI after the botched delete...
            catch
            {
                NotifyMessage("Company/s Can Not Be Deleted.  Contact XERP Admin For More Details.");
                Refresh();
            }
        }
        //Object.Property Scope Validation...
        private bool CompanyIsValid(Company item, _itemValidationProperties validationProperties, out string errorMessage)
        {
            errorMessage = "";
            switch (validationProperties)
            {
            case _itemValidationProperties.CompanyID:
                //validate key
                if (string.IsNullOrEmpty(item.CompanyID))
                {
                    errorMessage = "ID Is Required.";
                    return(false);
                }
                EntityStates entityState = GetCompanyState(item);
                if (entityState == EntityStates.Added && CompanyExists(item.CompanyID))
                {
                    errorMessage = "Item All Ready Exists...";
                    return(false);
                }
                //check cached list for duplicates...
                int count = CompanyList.Count(q => q.CompanyID == item.CompanyID);
                if (count > 1)
                {
                    errorMessage = "Item All Ready Exists...";
                    return(false);
                }
                break;

            case _itemValidationProperties.Name:
                //validate Description
                if (string.IsNullOrEmpty(item.Name))
                {
                    errorMessage = "Description Is Required.";
                    return(false);
                }
                break;
            }
            return(true);
        }
Example #4
0
        public ActionResult Index1()
        {
            try
            {
                var draw  = Request.Form.GetValues("draw").FirstOrDefault();
                var start = Request.Form.GetValues("start").FirstOrDefault();

                var length     = Request.Form.GetValues("length").FirstOrDefault();
                var sortColumn = Request.Form.GetValues("columns[" +
                                                        Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault();
                var sortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault();
                int pageSize      = length != null?Convert.ToInt32(length) : 0;

                string search = Request.Form.GetValues("search[value]")[0];
                int    skip   = start != null?Convert.ToInt32(start) : 0;

                IEnumerable <MVCCompanyModel> CompanyList;
                HttpResponseMessage           respose = GlobalVeriables.WebApiClient.GetAsync("CompanyInformations").Result;
                CompanyList = respose.Content.ReadAsAsync <IEnumerable <MVCCompanyModel> >().Result;

                if (!string.IsNullOrEmpty(search) && !string.IsNullOrWhiteSpace(search))
                {
                    // Apply search  on multiple field
                    CompanyList = CompanyList.Where(p => p.CompanyId.ToString().Contains(search) ||
                                                    p.ComapanyName.ToLower().Contains(search.ToLower()) ||
                                                    p.CompanyAddress.ToString().ToLower().Contains(search.ToLower()) ||
                                                    p.CompanyPhone.Contains(search.ToLower()) ||
                                                    p.CompanyCell.Contains(search.ToLower()) ||
                                                    p.CompanyEmail.ToString().ToLower().Contains(search.ToLower()) ||
                                                    p.CompanyTRN.Contains(search.ToLower())).ToList();
                }
                switch (sortColumn)
                {
                case "ComapanyName":
                    CompanyList = CompanyList.OrderBy(c => c.ComapanyName);
                    break;

                case "CompanyAddress":
                    CompanyList = CompanyList.OrderBy(c => c.CompanyAddress);
                    break;

                case "CompanyPhone":
                    CompanyList = CompanyList.OrderBy(c => c.CompanyPhone);
                    break;

                case "CompanyCell":
                    CompanyList = CompanyList.OrderBy(c => c.CompanyCell);
                    break;

                case "CompanyEmail":
                    CompanyList = CompanyList.OrderBy(c => c.CompanyEmail);
                    break;

                case "CompanyTRN":

                    CompanyList = CompanyList.OrderBy(c => c.CompanyTRN);
                    break;

                default:
                    CompanyList = CompanyList.OrderByDescending(c => c.CompanyId);
                    break;
                }

                //if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir)))
                //{
                //    var v = CompanyList.OrderBy(c=>c.);

                //}
                int recordsTotal = recordsTotal = CompanyList.Count();
                var data         = CompanyList.Skip(skip).Take(pageSize).ToList();
                return(Json(new { draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = data }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }

            return(View());
        }