Example #1
0
        public ActionResult MobileEditor(ICollection <InputObject> pageInputs, string method, string CID, string MSID, string MMID)
        {
            int MS_Id = 0, MM_Id = 0;
            int MFBID = 1;

            Int32.TryParse(MSID, out MS_Id);
            Int32.TryParse(MMID, out MM_Id);
            try
            {
                if (CID.Length < 6)
                {
                    throw new Exception("Location variable in wrong format");
                }

                Helpers.objectMapper <schedule> mapper = new Helpers.objectMapper <schedule>();
                schedule record = mapper.mapCollection(pageInputs);
                MFBID        = record.MFB_Id;
                record.MS_Id = MS_Id;

                if (record == null)
                {
                    throw new Exception("ERROR: could not map page inputs.  Contact helper desk to log bug.");
                }
                switch (method.ToUpper())
                {
                case "SUBMIT":
                    Save(CID, record);
                    break;

                case "DELETE":
                    delete(CID, record);
                    break;

                default:
                    throw new Exception("ERROR: NO METHOD RECIEVED");
                }
            } catch (Exception ex)
            {
                Models.MobileEditorModel model = getEditorModelObject(CID, MS_Id, MFBID, MM_Id);
                model.CID   = CID;
                model.MS_Id = MS_Id;
                model.MM_Id = MM_Id;

                if (model.inputs.Count > 0)
                {
                    model.inputs[0].errorFlag    = true;
                    model.inputs[0].errorMessage = ex.Message;
                }
                model.inputs = mapScheduleValues(model.inputs, model.MS_Id, model.CID);
                return(View(model));
            }

            return(RedirectToAction("Index", "Home", new { CID = CID }));
        }
Example #2
0
        private IList <Helpers.PageInput> mapScheduleValues(IList <Helpers.PageInput> mobileInputs, int MS_Id, string CID)
        {
            if (MS_Id == 0)
            {
                return(mobileInputs);
            }

            Helpers.CtxService service = new Helpers.CtxService(null, CID);

            Models.EF.Maintenance_Schedule schedule = service.getScheduleRecord(MS_Id);

            if (schedule == null)
            {
                return(mobileInputs);
            }

            Helpers.objectMapper <Maintenance_Schedule> mapper = new Helpers.objectMapper <Maintenance_Schedule>();

            Hashtable hash = mapper.createPropertyInfoHash();

            ICollection keys = hash.Keys;

            if (keys.Count > 0)
            {
                foreach (var item in mobileInputs)
                {
                    try
                    {
                        if (hash[item.input.id.ToUpper()] != null)
                        {
                            PropertyInfo info = (PropertyInfo)hash[item.input.id.ToUpper()];
                            if (info != null && item.input != null)
                            {
                                var val = info.GetValue(schedule);
                                if (val == null)
                                {
                                    val = "";
                                }
                                if (info.PropertyType.Name.ToUpper() == "DATETIME")
                                {
                                    DateTime realdate = Convert.ToDateTime(val);
                                    item.input.value = realdate.ToString("yyyy-MM-dd");
                                }
                                else
                                {
                                    item.input.value = mapper.ConvertType(val.ToString(), "STRING").ToString();
                                }
                            }
                        }
                    } catch (Exception ex)
                    {
                        if (item.input != null)
                        {
                            item.errorFlag    = true;
                            item.errorMessage = ex.Message;
                        }
                    }
                }
            }

            return(mobileInputs);
        }