Ejemplo n.º 1
0
        public ActionResult DeleteTimeEntry(int id)
        {
            // Delete the time entry from the database
            var result = _processor.DeleteTimeEntry(id);

            // Return either the updated list or an error message
            if (result.IsSuccessful)
            {
                return(GetTimeEntries());
            }

            return(Content(result.ErrorMessage));
        }
Ejemplo n.º 2
0
        public ActionResult SaveTimeEntry(TimeEntryModel model, string oper, string id)
        {
            IOpResult result;

            switch (oper)
            {
            case "edit":
                result = _processor.UpdateTimeEntry(model.ToEntity());
                break;

            case "add":
                result = _processor.AddTimeEntry(model.ToEntity(), User.Identity.Name);
                break;

            case "del":
                result = _processor.DeleteTimeEntry(int.Parse(id));
                break;

            default:
                result = new OpResult
                {
                    IsSuccessful = false,
                    ErrorMessage = string.Format("{0} is an unsupported operation.", oper)
                };
                break;
            }

            // Return an empty string
            if (result.IsSuccessful)
            {
                return(Content(string.Empty));
            }

            // Return the error message
            HttpContext.Response.StatusCode = 500;
            return(Content(result.ErrorMessage));
        }