Ejemplo n.º 1
0
        public JsonResult Edit(Cause model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Json(new { Result = "ERROR", Message = "Form is not valid! Please correct it and try again." }));
                }

                //check dupliate when edit item before save to database , itemcount should be no over 2
                var itemCount = CauseManager.GetCountDuplicate(model.sDescription.Trim());
                if (itemCount > 1)
                {
                    return(Json(new { Result = "ERROR", Message = "Cause already exists." }));
                }

                //check item found
                Cause itemFound = CauseManager.GetById(model.kCauseId);
                if (itemFound == null)
                {
                    return(Json(new { Result = "ERROR", Message = "Item Not Found" }));
                }
                model.dtDateAdd    = itemFound.dtDateAdd;
                model.dtDateUpdate = DateTime.Now;

                CauseManager.Edit(model);
                return(Json(new { Result = "OK" }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
Ejemplo n.º 2
0
        public JsonResult GetById(Guid Id)
        {
            try
            {
                Cause itemFound = CauseManager.GetById(Id);

                return(Json(itemFound, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }