Beispiel #1
0
        public static string Update(SiteSettings ss, int deptId)
        {
            var deptModel = new DeptModel(ss, deptId, setByForm: true);
            var invalid   = DeptValidators.OnUpdating(ss, deptModel);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(invalid.MessageJson());
            }
            if (deptModel.AccessStatus != Databases.AccessStatuses.Selected)
            {
                return(Messages.ResponseDeleteConflicts().ToJson());
            }
            var error = deptModel.Update(ss);

            if (error.Has())
            {
                return(error == Error.Types.UpdateConflicts
                    ? Messages.ResponseUpdateConflicts(deptModel.Updator.Name).ToJson()
                    : new ResponseCollection().Message(error.Message()).ToJson());
            }
            else
            {
                var res = new DeptsResponseCollection(deptModel);
                return(ResponseByUpdate(res, ss, deptModel)
                       .PrependComment(ss, deptModel.Comments, deptModel.VerType)
                       .ToJson());
            }
        }
Beispiel #2
0
        public static string Update(Context context, SiteSettings ss, int deptId)
        {
            var deptModel = new DeptModel(
                context: context, ss: ss, deptId: deptId, setByForm: true);
            var invalid = DeptValidators.OnUpdating(
                context: context, ss: ss, deptModel: deptModel);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(invalid.MessageJson());
            }
            if (deptModel.AccessStatus != Databases.AccessStatuses.Selected)
            {
                return(Messages.ResponseDeleteConflicts().ToJson());
            }
            var error = deptModel.Update(context: context, ss: ss);

            switch (error)
            {
            case Error.Types.None:
                var res = new DeptsResponseCollection(deptModel);
                return(ResponseByUpdate(res, context, ss, deptModel)
                       .PrependComment(
                           context: context,
                           ss: ss,
                           column: ss.GetColumn(context: context, columnName: "Comments"),
                           comments: deptModel.Comments,
                           verType: deptModel.VerType)
                       .ToJson());

            case Error.Types.UpdateConflicts:
                return(Messages.ResponseUpdateConflicts(
                           deptModel.Updator.Name)
                       .ToJson());

            default:
                return(error.MessageJson());
            }
        }