/// <summary>
 ///     Adding or Updating Sport Type in a database
 /// </summary>
 /// <param name="sportType">Business Object Sport Type</param>
 /// <returns>True if succeeded and false otherwise</returns>
 public async Task <bool> SaveSportType(DtoSportType sportType)
 {
     try
     {
         using (var data = Context)
         {
             var st =
                 await
                     (from item in data.SportType where sportType.Id == item.id select item).FirstOrDefaultAsync();
             // Updating Sport Type
             if (st != null)
             {
                 st.name        = sportType.Name;
                 st.description = sportType.Description;
             }
             // Adding new Sport Type
             else
             {
                 if (await(from item in data.SportType where sportType.Name == item.name select item).AnyAsync())
                 {
                     return(false);
                 }
                 data.SportType.Add(SportTypeConverter.DtoToDataAccess(sportType));
             }
             await data.SaveChangesAsync();
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
示例#2
0
 /// <summary>
 ///     Conversion from DTO to View Model
 /// </summary>
 /// <param name="sportType">DTO Sport Type Object</param>
 /// <returns>View Model Sport Type Object</returns>
 public static SportType DtoToViewModel(DtoSportType sportType)
 {
     return(new SportType
     {
         Id = sportType.Id,
         Name = sportType.Name,
         Description = sportType.Description
     });
 }
 /// <summary>
 ///     Conversion from dto to data Object
 /// </summary>
 /// <param name="sportType">dto Sport Type Object</param>
 /// <returns>Data Access Sport Type Object</returns>
 public static SportType DtoToDataAccess(DtoSportType sportType)
 {
     return(new SportType
     {
         id = sportType.Id,
         name = sportType.Name,
         description = sportType.Description
     });
 }