private void AddMealRelatedInfo(Request <MealCreate> request, int mealId) { try { if (request.Data.AttributeGroups != null && request.Data.AttributeGroups.Count > 0) { var mealAttributeGroupService = MealAttributeGroupService.GetInstance(); foreach (var id in request.Data.AttributeGroups) { mealAttributeGroupService.Create(new Request <MealAttributeGroupCreate> { UserId = request.UserId, Data = new MealAttributeGroupCreate { MealId = mealId, AttributeGroupId = id } }); } } if (request.Data.Attributes != null && request.Data.Attributes.Count > 0) { var mealAttributeService = MealAttributeService.GetInstance(); foreach (var id in request.Data.Attributes) { mealAttributeService.Create(new Request <MealAttributeCreate> { UserId = request.UserId, Data = new MealAttributeCreate { AttributeId = id, MealId = mealId } }); } } if (request.Data.MealImages != null && request.Data.MealImages.Count > 0) { var imageService = ImageService.GetInstance(); foreach (var image in request.Data.MealImages) { imageService.Create(new Request <ImageCreate> { UserId = request.UserId, Data = new ImageCreate { Content = image.Content, IsDefault = image.IsDefualt, SourceId = mealId, SourceType = Enums.SourceType.Meal } }); } } } catch (RestaurantException ex) { throw ex; } catch (Exception e) { throw e; } }
/// <summary> /// singlton /// </summary> /// <returns>meal attribute group service object</returns> public static MealAttributeGroupService GetInstance() { if (_instance == null) { lock (lockObj) { if (_instance == null) { _instance = new MealAttributeGroupService(); } } } return(_instance); }