Exemple #1
0
        public ActionResult Edit(OpticalCable cable)
        {
            JsonResult ret = new JsonResult();

            try
            {
                EditModelToContext(cable);
                //删除旧的
                var fibers = db.OpticalFiber.Where(of => of.OC_ID == cable.ID);
                db.OpticalFiber.RemoveRange(fibers.ToArray());
                for (int i = 0; i < cable.OC_FiberCount; ++i)
                {
                    OpticalFiber fiber = new OpticalFiber
                    {
                        OF_Name        = string.Format("#{0}", i + 1),
                        OC_ID          = cable.ID,
                        OC_Name        = cable.OC_Name,
                        OC_TotalLength = cable.OC_TotalLength
                    };
                    AddModelToContext(fiber);
                }
                db.SaveChanges();
                ret.Data = JsonConvert.SerializeObject(new
                {
                    status  = 0,
                    message = "",
                    data    = cable
                });
            }
            catch (Exception ex)
            {
                ret.Data = JsonConvert.SerializeObject(new
                {
                    status  = 1,
                    message = ex.Message,
                    data    = cable
                });
            }
            return(ret);
        }
Exemple #2
0
        public ActionResult Create(OpticalCable cable)
        {
            JsonResult ret = new JsonResult();

            try
            {
                AddModelToContext(cable);
                for (int i = 0; i < cable.OC_FiberCount; ++i)
                {
                    OpticalFiber fiber = new OpticalFiber
                    {
                        OF_Name        = string.Format("#{0}", i + 1),
                        OC_ID          = cable.ID,
                        OC_Name        = cable.OC_Name,
                        OC_TotalLength = cable.OC_TotalLength
                    };
                    AddModelToContext(fiber);
                }
                db.SaveChanges();
                ret.Data = JsonConvert.SerializeObject(new
                {
                    status  = 0,
                    message = "",
                    data    = cable
                });
            }
            catch (Exception ex)
            {
                ret.Data = JsonConvert.SerializeObject(new
                {
                    status  = 1,
                    message = ex.Message,
                    data    = ""
                });
            }
            return(ret);
        }