Exemple #1
0
        public async Task Add(RawMaterialInputDto input)
        {
            var userId = ((UserIdentity)User.Identity).UserId;

            if (await db.RawMaterials.AnyAsync(m => m.Name == input.Name && !m.IsDelete))
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = input.Name + "已存在禁止重复添加"
                    }))
                });
            }

            var data = new RawMaterial()
            {
                Id                = IdentityManager.NewId(),
                Abbreviation      = input.Abbreviation,
                EnglishName       = input.EnglishName,
                AppearanceState   = input.AppearanceState,
                BeCommonlyCalled1 = input.BeCommonlyCalled1,
                BeCommonlyCalled2 = input.BeCommonlyCalled2,
                CASNumber         = input.CASNumber,
                EntryPersonId     = userId,
                MolecularFormula  = input.MolecularFormula,
                MolecularWeight   = input.MolecularWeight,
                Name              = input.Name,
                RawMaterialType   = input.RawMaterialType,
                StructuralFormula = input.StructuralFormula,
                WarehousingTypeId = input.WarehousingTypeId,
                IsDelete          = false,
                CompanyId         = input.CompanyId
            };

            db.RawMaterials.Add(data);

            if (await db.SaveChangesAsync() <= 0)
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = "添加失败"
                    }))
                });
            }
        }
Exemple #2
0
        public async Task Update(RawMaterialInputDto input)
        {
            var data = await db.RawMaterials.SingleOrDefaultAsync(m => m.Id == input.RawMaterialId && !m.IsDelete);

            if (data != null)
            {
                data.Abbreviation      = input.Abbreviation;
                data.EnglishName       = input.EnglishName;
                data.AppearanceState   = input.AppearanceState;
                data.BeCommonlyCalled1 = input.BeCommonlyCalled1;
                data.BeCommonlyCalled2 = input.BeCommonlyCalled2;
                data.CASNumber         = input.CASNumber;
                data.CompanyId         = input.CompanyId;
                data.MolecularFormula  = input.MolecularFormula;
                data.MolecularWeight   = input.MolecularWeight;
                data.Name              = input.Name;
                data.RawMaterialType   = input.RawMaterialType;
                data.StructuralFormula = input.StructuralFormula;
                data.WarehousingTypeId = input.WarehousingTypeId;
            }
            else
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = "该基础资料不存在"
                    }))
                });
            }

            if (await db.SaveChangesAsync() <= 0)
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = "更新失败"
                    }))
                });
            }
        }