예제 #1
0
        public ActionResult CreateMaterial(Guid?id)
        {
            MaterialRepository      repository      = new MaterialRepository(false);
            EXP_DrugDeclaration     drugDeclaration = null;
            CreateMaterialViewModel vm = new CreateMaterialViewModel()
            {
                DrugDeclarationId = id,
                Id = null
            };

            if (id.HasValue)
            {
                //EXP_Materials material = new EXP_Materials(){};
                drugDeclaration = repository.GetDrugDeclaration(d => d.Id == id).Include(d => d.sr_dosage_forms).First();
                if (drugDeclaration.DrugFormId != null)
                {
                    vm.DrugFormId   = drugDeclaration.DrugFormId;
                    vm.DrugFormName = drugDeclaration.sr_dosage_forms.name;

                    vm.IsNpp = repository.GetIsControlFormDrugDeclaration(id.Value);
                }
            }

            return(View(vm));
        }
예제 #2
0
        public ActionResult EditMaterial(Guid id)
        {
            MaterialRepository repository = new MaterialRepository(false);
            var DrugDeclarationId         = repository.GetAsQuarable(m => m.Id == id).Select(m => m.DrugDeclarationId).FirstOrDefault();

            CreateMaterialViewModel vm = new CreateMaterialViewModel()
            {
                DrugDeclarationId = DrugDeclarationId,
                Id = id
            };

            return(View("CreateMaterial", vm));
        }
        public object CreateMaterial(CreateMaterialViewModel createMaterialViewModel)
        {
            if (!ModelState.IsValid)
                return Request.CreateResponse(HttpStatusCode.BadRequest, new BaseResponse(ResponseStatus.ValidationError.ToString(), ModelState.Values.ToList()[0].Errors[0].ErrorMessage));

            CurrentUserInfo currentUserInfo = _tokenHelper.GetUserInfo();

            MaterialData materialData =
                CreateMaterialViewModel.GetMaterialData(currentUserInfo.Id, createMaterialViewModel);

            _materialLogic.Add(materialData);

            return Request.CreateResponse(HttpStatusCode.OK, new BaseResponse(ResponseStatus.Success.ToString(),
                ResponseMessagesModel.Success));
        }
예제 #4
0
        public ActionResult MaterialListPartialVew(Guid?ddId)
        {
            DictionaryRepository repository = new DictionaryRepository();
            Guid?mpSample = repository.GetDictionaryElementIdByTypeAndCode(Dictionary.MaterialRdType.DicCode, Dictionary.MaterialRdType.MpSample);
            CreateMaterialViewModel model = new CreateMaterialViewModel()
            {
                DrugDeclarationId = ddId
            };

            if (mpSample.HasValue)
            {
                model.TypeIdDefaultValue = mpSample.Value;
            }

            return(PartialView(model));
        }
예제 #5
0
        public async Task <ActionResult> Create(CreateMaterialViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Material material = new Material
            {
                Name = model.Name
            };

            if (context.Materials.Any())
            {
                material.Id = context.Materials.Max(t => t.Id) + 1;
            }
            else
            {
                material.Id = 1;
            }

            context.Materials.Add(material);

            try
            {
                await context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                string errorMessage = ex.Message;

                while (ex != null)
                {
                    errorMessage = ex.Message;
                    ex           = ex.InnerException;
                }

                ModelState.AddModelError("", errorMessage);

                return(View(model));
            }

            return(RedirectToAction(nameof(Index)));
        }