Exemplo n.º 1
0
        public static List <TimeModel> SelectAllByProjectId(string projectId)
        {
            var timeNodes = GetDataBaseXDocumentInstance
                            .Descendants(Constants.TimeNodeName)
                            .Where(q => q.HasAttributes &&
                                   q.Attribute(nameof(TimeModel.ProjectId)) != null &&
                                   q.Attribute(nameof(TimeModel.ProjectId)).Value.Equals(projectId, StringComparison.InvariantCultureIgnoreCase))
                            .ToList();
            var times = new List <TimeModel>();

            foreach (var xElement in timeNodes)
            {
                times.Add(new TimeModel
                {
                    Id               = Guid.Parse(xElement.Attribute(nameof(TimeModel.Id)).Value),
                    ProjectId        = int.Parse(xElement.Attribute(nameof(TimeModel.ProjectId)).Value),
                    Description      = xElement.Attribute(nameof(TimeModel.Description)).Value,
                    StartDateTime    = DateTime.Parse(xElement.Attribute(nameof(TimeModel.StartDateTime)).Value),
                    StopDateTime     = DateTime.Parse(xElement.Attribute(nameof(TimeModel.StopDateTime)).Value),
                    Duration         = xElement.Attribute(nameof(TimeModel.Duration)).Value.StandardTimeSpanParse(),
                    RegisterDateTime = DateTime.Parse(xElement.Attribute(nameof(TimeModel.RegisterDateTime)).Value)
                });
            }
            return(times.OrderByDescending(q => q.RegisterDateTime).ToList());
        }
Exemplo n.º 2
0
 private static int GetMaxId()
 {
     return GetDataBaseXDocumentInstance
         .Descendants(Constants.ProjectNodeName)
         .Where(q => q.HasAttributes && q.Attribute(nameof(ProjectModel.Id)) != null)
         .Max(q => q.Attribute(nameof(ProjectModel.Id)) == null || string.IsNullOrWhiteSpace(q.Attribute(nameof(ProjectModel.Id)).Value) ? 0 : int.Parse(q.Attribute(nameof(ProjectModel.Id)).Value));
 }
Exemplo n.º 3
0
 private static XElement GetElement(string startDateTime, string stopDateTime)
 {
     return(GetDataBaseXDocumentInstance
            .Descendants(Constants.TimeNodeName)
            .FirstOrDefault(q => q.HasAttributes &&
                            q.Attribute(nameof(TimeModel.StartDateTime)) != null && q.Attribute(nameof(TimeModel.StartDateTime)).Value.Equals(startDateTime, StringComparison.InvariantCultureIgnoreCase) &&
                            q.Attribute(nameof(TimeModel.StopDateTime)) != null && q.Attribute(nameof(TimeModel.StopDateTime)).Value.Equals(stopDateTime, StringComparison.InvariantCultureIgnoreCase)));
 }
Exemplo n.º 4
0
 private static XElement GetElement(string projectId)
 {
     return GetDataBaseXDocumentInstance
         .Descendants(Constants.ProjectNodeName)
         .FirstOrDefault(q => q.HasAttributes &&
             q.Attribute(nameof(ProjectModel.Id)) != null &&
             q.Attribute(nameof(ProjectModel.Id)).Value.Equals(projectId, StringComparison.InvariantCultureIgnoreCase));
 }
Exemplo n.º 5
0
 public static void Delete(int id)
 {
     var idString = id.ToString();
     var projectElement = GetElement(idString);
     if (projectElement == null)
         throw new Exception($"Project with {id} Id is not exist in DataBase");
     projectElement.RemoveAll();
     var times = GetDataBaseXDocumentInstance.Descendants(Constants.TimeNodeName)
         .Where(q => q.HasAttributes && q.Attribute(nameof(TimeModel.ProjectId)) != null &&
                     q.Attribute(nameof(TimeModel.ProjectId)).Value.Equals(idString));
     times.Remove();
     projectElement.Remove();
     SaveChanges();
 }