Exemple #1
0
        public async Task <MedicamentRegistrationDTO> CreateMedicament(MedicamentRegistrationDTO MedicamentRegistrationDTO)
        {
            Medicament medicament = new Medicament {
                CategoryId = MedicamentRegistrationDTO.CategoryId, ManufacturerId = MedicamentRegistrationDTO.ManufacturerId
            };
            await db.Medicaments.AddAsync(medicament);

            List <Lang>        langs = db.Langs.ToList();
            MedicamentLangLink medicamentLangLinkENG = new MedicamentLangLink
            {
                Description    = MedicamentRegistrationDTO.DescriptionENG,
                MedicamentName = MedicamentRegistrationDTO.MedicamentNameENG,
                Medicament     = medicament,
                Lang           = langs.Where(p => p.Name == "ENG").First()
            };
            MedicamentLangLink medicamentLangLinkRUS = new MedicamentLangLink
            {
                Description    = MedicamentRegistrationDTO.DescriptionRUS,
                MedicamentName = MedicamentRegistrationDTO.MedicamentNameRUS,
                Medicament     = medicament,
                Lang           = langs.Where(p => p.Name == "RUS").First()
            };
            MedicamentLangLink medicamentLangLinkTKM = new MedicamentLangLink
            {
                Description    = MedicamentRegistrationDTO.DescriptionTKM,
                MedicamentName = MedicamentRegistrationDTO.MedicamentNameTKM,
                Medicament     = medicament,
                Lang           = langs.Where(p => p.Name == "TKM").First()
            };
            await db.MedicamentLangLinks.AddRangeAsync(medicamentLangLinkENG, medicamentLangLinkRUS, medicamentLangLinkTKM);

            await db.SaveChangesAsync();

            return(MedicamentRegistrationDTO);
        }
Exemple #2
0
 public async Task <ActionResult <MedicamentRegistrationDTO> > CreateMedicament(MedicamentRegistrationDTO MedicamentRegistrationDTO)
 {
     try
     {
         await serv.CreateMedicament(MedicamentRegistrationDTO);
     }
     catch (Exception ex)
     {
         var err = new { error = ex.Message };
         return(Ok(err));
     }
     return(Ok(MedicamentRegistrationDTO));
 }