Exemple #1
0
        public static (bool valid, string explanation) ValidateCreatedAndUpdatedBy(
            ICreatedAndLastUpdateOnAndBy toValidate, bool isNewEntry)
        {
            var isValid      = true;
            var errorMessage = new List <string>();

            if (toValidate.CreatedOn == DateTime.MinValue)
            {
                isValid = false;
                errorMessage.Add($"Created on of {toValidate.CreatedOn} is not valid.");
            }

            var createdByValidation = ValidateCreatedBy(toValidate.CreatedBy);

            if (!createdByValidation.valid)
            {
                isValid = false;
                errorMessage.Add(createdByValidation.explanation);
            }

            if (!isNewEntry && string.IsNullOrWhiteSpace(toValidate.LastUpdatedBy))
            {
                isValid = false;
                errorMessage.Add("Updated by can not be blank when updating an entry");
            }

            if (!isNewEntry && toValidate.LastUpdatedOn == null || toValidate.LastUpdatedOn == DateTime.MinValue)
            {
                isValid = false;
                errorMessage.Add("Last Updated On can not be blank/empty when updating an entry");
            }

            return(isValid, string.Join(Environment.NewLine, errorMessage));
        }
        public static HtmlTag PostCreatedByAndUpdatedOnDiv(ICreatedAndLastUpdateOnAndBy dbEntry)
        {
            var titleContainer = new HtmlTag("div").AddClass("post-title-area-created-and-updated-container");

            titleContainer.Children.Add(new HtmlTag("h3").AddClass("post-title-area-created-and-updated-content")
                                        .Text(CreatedByAndUpdatedOnString(dbEntry)));
            return(titleContainer);
        }
        public static HtmlTag CreatedByAndUpdatedOnDiv(ICreatedAndLastUpdateOnAndBy dbEntry)
        {
            var titleContainer = new DivTag().AddClass("created-and-updated-container");

            titleContainer.Children.Add(new DivTag().AddClass("created-and-updated-content")
                                        .Text(CreatedByAndUpdatedOnString(dbEntry)));
            return(titleContainer);
        }
        public static DateTime?LatestCreatedOnOrUpdatedOn(ICreatedAndLastUpdateOnAndBy dbEntry)
        {
            if (dbEntry == null)
            {
                return(null);
            }

            return(dbEntry.LastUpdatedOn ?? dbEntry.CreatedOn);
        }
        public static HtmlTag PageCreatedDiv(ICreatedAndLastUpdateOnAndBy createdBy)
        {
            var createdByDiv = new DivTag().AddClass("created-by-container");

            createdByDiv.Children.Add(new HtmlTag("div").AddClass("created-title"));

            createdByDiv.Children.Add(new HtmlTag("p").AddClass("created-by-content").Text(
                                          $"Page Created by {createdBy.CreatedBy}, {createdBy.CreatedOn:M/d/yyyy}"));

            return(createdByDiv);
        }
        public static string NoteCreatedByAndUpdatedOnString(ICreatedAndLastUpdateOnAndBy dbEntry)
        {
            var createdUpdatedString = $"{dbEntry.CreatedBy}";

            var onlyCreated = false;

            if (dbEntry.LastUpdatedOn != null && dbEntry.CreatedOn.Date == dbEntry.LastUpdatedOn.Value.Date)
            {
                if (string.Compare(dbEntry.CreatedBy, dbEntry.LastUpdatedBy, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    createdUpdatedString = $"{dbEntry.LastUpdatedBy} ";
                    onlyCreated          = true;
                }
            }

            createdUpdatedString += $" {dbEntry.CreatedOn:M/d/yyyy}";

            if (onlyCreated)
            {
                return(createdUpdatedString.Trim());
            }

            if (string.IsNullOrWhiteSpace(dbEntry.LastUpdatedBy) && dbEntry.LastUpdatedOn == null)
            {
                return(createdUpdatedString);
            }

            if (dbEntry.LastUpdatedOn != null && dbEntry.CreatedOn.Date == dbEntry.LastUpdatedOn.Value.Date)
            {
                return(createdUpdatedString);
            }

            var updatedString = ", Updated";

            if (!string.IsNullOrWhiteSpace(dbEntry.LastUpdatedBy))
            {
                updatedString += $" by {dbEntry.LastUpdatedBy}";
            }

            if (dbEntry.LastUpdatedOn != null)
            {
                updatedString += $" {dbEntry.LastUpdatedOn.Value:M/d/yyyy}";
            }

            return((createdUpdatedString + updatedString).Trim());
        }
        public static string CreatedByAndUpdatedOnString(ICreatedAndLastUpdateOnAndBy dbEntry)
        {
            var createdUpdatedString = $"Created by {dbEntry.CreatedBy}";

            var onlyCreated = false;

            if (dbEntry.LastUpdatedOn != null && dbEntry.CreatedOn.Date == dbEntry.LastUpdatedOn.Value.Date)
            {
                if (string.Compare(dbEntry.CreatedBy, dbEntry.LastUpdatedBy, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    createdUpdatedString = $"Created and Updated by {dbEntry.LastUpdatedBy}";
                    onlyCreated          = true;
                }
            }

            createdUpdatedString += $" on {CreatedByAndUpdatedOnFormattedDateTimeString(dbEntry.CreatedOn)}.";

            if (onlyCreated)
            {
                return(createdUpdatedString.Trim());
            }

            if (string.IsNullOrWhiteSpace(dbEntry.LastUpdatedBy) && dbEntry.LastUpdatedOn == null)
            {
                return(createdUpdatedString);
            }

            var updatedString = " Updated";

            if (!string.IsNullOrWhiteSpace(dbEntry.LastUpdatedBy) && dbEntry.CreatedBy != dbEntry.LastUpdatedBy)
            {
                updatedString += $" by {dbEntry.LastUpdatedBy}";
            }

            if (dbEntry.LastUpdatedOn != null)
            {
                updatedString += $" on {CreatedByAndUpdatedOnFormattedDateTimeString(dbEntry.LastUpdatedOn.Value)}";
            }

            updatedString += ".";

            return((createdUpdatedString + updatedString).Trim());
        }
Exemple #8
0
 public CreatedAndUpdatedByAndOnDisplayContext(StatusControlContext statusContext,
                                               ICreatedAndLastUpdateOnAndBy dbEntry)
 {
     StatusContext = statusContext ?? new StatusControlContext();
     StatusContext.RunFireAndForgetTaskWithUiToastErrorReturn(() => LoadData(dbEntry));
 }