示例#1
0
        private static EfWorkType GetOrCreateWorkType(string id, string name,
                                                      BiblioDbContext context)
        {
            // force a valid type
            if (id == null)
            {
                id = "-";
            }
            if (name == null)
            {
                name = id;
            }

            // get it
            EfWorkType ef = context.WorkTypes.Find(id);

            if (ef == null)
            {
                ef = new EfWorkType
                {
                    Id   = id,
                    Name = name
                };
                context.WorkTypes.Add(ef);
            }
            else if (name != null)
            {
                ef.Name = name;
            }

            return(ef);
        }
示例#2
0
 /// <summary>
 /// Gets the work's type corresponding to the specified work type entity.
 /// </summary>
 /// <param name="ef">The entity or null.</param>
 /// <returns>The work type or null.</returns>
 public static WorkType GetWorkType(EfWorkType ef)
 {
     if (ef == null)
     {
         return(null);
     }
     return(new WorkType
     {
         Id = ef.Id,
         Name = ef.Name
     });
 }
示例#3
0
 /// <summary>
 /// Deletes the type with the specified ID.
 /// </summary>
 /// <param name="id">The ID.</param>
 public void DeleteWorkType(string id)
 {
     using (var db = GetContext())
     {
         EfWorkType ef = db.WorkTypes.Find(id);
         if (ef != null)
         {
             db.WorkTypes.Remove(ef);
             db.SaveChanges();
         }
     }
 }
示例#4
0
        /// <summary>
        /// Adds or updates the type with the specified ID and name.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <exception cref="ArgumentNullException">type</exception>
        public void AddWorkType(WorkType type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            using (var db = GetContext())
            {
                EfWorkType ef = EfHelper.GetEfWorkType(type, db);
                db.SaveChanges();
            }
        }
示例#5
0
        /// <summary>
        /// Gets the type with the specified ID.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns>The type, or null if not found.</returns>
        /// <exception cref="ArgumentNullException">id</exception>
        public WorkType GetWorkType(string id)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            using (var db = GetContext())
            {
                EfWorkType ef = db.WorkTypes.Find(id);
                return(EfHelper.GetWorkType(ef));
            }
        }
示例#6
0
        /// <summary>
        /// Gets the work entity corresponding to the specified type.
        /// </summary>
        /// <param name="type">The type or null.</param>
        /// <param name="context">The context.</param>
        /// <returns>The entity or null.</returns>
        public static EfWorkType GetEfWorkType(WorkType type,
                                               BiblioDbContext context)
        {
            if (type == null)
            {
                return(null);
            }

            EfWorkType ef = type.Id != null
                ? context.WorkTypes.Find(type.Id) : null;

            if (ef == null)
            {
                ef = new EfWorkType
                {
                    Id = type.Id
                };
                context.WorkTypes.Add(ef);
            }
            ef.Name = type.Name;

            return(ef);
        }