예제 #1
0
        public async Task <ActionResult> OnPost()
        {
            if (ModelState.IsValid)
            {
                if (!(await MaterialAlloyDataAccess.CheckIfDescriptionIsUnique(Description)))
                {
                    Message = new PopUpMessageModel()
                    {
                        IsMessageGood = false,
                        Text          = "A material alloy already exists with that description."
                    };

                    await SetUpProperties();

                    return(Page());
                }

                var alloyToAdd = new MaterialAlloyModel()
                {
                    Description      = Description,
                    MaterialSeriesId = SeriesId
                };

                var result = await MaterialAlloyDataAccess.CreateMaterialAlloy(alloyToAdd); //Not sure what to do with the result.  It will just be the alloy passed in but with an updated alloyId.

                return(RedirectToPage("MaterialAlloyEntry", new { aMessage = "Alloy saved successfully", isMessageGood = true }));
            }
            else
            {
                await SetUpProperties();

                return(Page());
            }
        }
예제 #2
0
 public static MaterialAlloy ToEntity(this MaterialAlloyModel aMaterialAlloyModel)
 {
     return(new MaterialAlloy()
     {
         Description = aMaterialAlloyModel.Description,
         MaterialSeriesId = aMaterialAlloyModel.MaterialSeriesId
     });
 }
예제 #3
0
        public async Task <MaterialAlloyModel> CreateMaterialAlloy(MaterialAlloyModel aMaterialAlloyModel)
        {
            var entityToAdd = aMaterialAlloyModel.ToEntity();

            var lastIdUsed = await Context.MaterialAlloy.MaxAsync(i => i.MaterialAlloyId);

            entityToAdd.MaterialAlloyId = (lastIdUsed + 1);

            Context.MaterialAlloy.Add(entityToAdd);
            await Context.SaveChangesAsync();

            return(entityToAdd.ToModel());
        }
예제 #4
0
        public async Task <ActionResult <MaterialAlloyModel> > CreateMaterialAlloy(MaterialAlloyModel aMaterialAlloyModel)
        {
            try
            {
                var data = await MaterialAlloyService.CreateMaterialAlloy(aMaterialAlloyModel);

                return(Ok(JsonSerializer.Serialize(data)));
            }
            catch (Exception ex)
            {
                _logger.LogError("MaterialAlloyController.CreateMaterialAlloy(MaterialAlloyModel aMaterialAlloyModel) Not able to create material alloy ({materialAlloyModel}). | Message: {exMessage} | StackTrace: {stackTrace}", JsonSerializer.Serialize(aMaterialAlloyModel), ex.Message, ex.StackTrace);
                return(BadRequest(ex.Message));
            }
        }
예제 #5
0
 public async Task <MaterialAlloyModel> CreateMaterialAlloy(MaterialAlloyModel aMaterialAlloyModel)
 {
     return(await DataAccessGeneric.HttpPostRequest <MaterialAlloyModel>(Config["APIAddress"] + "api/MaterialAlloy/CreateMaterialAlloy", aMaterialAlloyModel, _httpContextAccessor.HttpContext));
 }