Пример #1
0
        public async Task <string> AddTreatment(long foodId, int treamentId, int providerId, int createById)
        {
            var Treament = await _treatmentRepository.FindAllAsync(t => t.TreatmentParentId == treamentId);

            var FoodData = await GetFoodDataByID(foodId);

            if (!ValidateFoodData(FoodData, foodId))
            {
                throw new InvalidDataException(MessageConstant.IVALID_DATA);
            }
            List <string> TreatmentProcess = new List <string>();

            for (int i = 0; i < Treament.Count; i++)
            {
                TreatmentProcess.Add(Treament[i].Name);
            }
            foreach (var p in FoodData.Providers)
            {
                if (p.ProviderId == providerId)
                {
                    p.Treatment = new Treatments()
                    {
                        TreatmentDate    = DateTime.Now,
                        TreatmentProcess = new List <string>()
                    };
                    p.Treatment.TreatmentProcess = TreatmentProcess;
                }
            }
            FoodData.Providers[0].Treatment.TreatmentProcess = TreatmentProcess;
            var setting = new JsonSerializerSettings()
            {
                NullValueHandling = NullValueHandling.Ignore
            };
            string newData = JsonConvert.SerializeObject(TreatmentProcess, setting);

            return(await _service.SaveFoodData(FoodData, newData, _userRepository.GetById(createById).Username));
        }