Exemplo n.º 1
0
        public async Task <IHttpActionResult> AddOffice(Z_OfficeDto z_OfficeDto)
        {
            try
            {
                var      userId   = ((UserIdentity)User.Identity).UserId;
                Z_Office z_Office = new Z_Office
                {
                    Id                = IdentityManager.NewId(),
                    Name              = z_OfficeDto.Name,
                    Encoding          = z_OfficeDto.Encoding,
                    EntryPersonId     = z_OfficeDto.EntryPersonId,
                    Desc              = z_OfficeDto.Desc,
                    CompanyId         = z_OfficeDto.Companyid,
                    Z_OfficeTypeid    = z_OfficeDto.Z_OfficeTypeid,
                    EnglishName       = z_OfficeDto.EnglishName,
                    Abbreviation      = z_OfficeDto.Abbreviation,
                    BeCommonlyCalled1 = z_OfficeDto.BeCommonlyCalled1,
                    BeCommonlyCalled2 = z_OfficeDto.BeCommonlyCalled2,
                    CASNumber         = z_OfficeDto.CASNumber,
                    MolecularWeight   = z_OfficeDto.MolecularWeight,
                    MolecularFormula  = z_OfficeDto.MolecularFormula,
                    StructuralFormula = z_OfficeDto.StructuralFormula,
                    Density           = z_OfficeDto.Density,
                    Statement         = z_OfficeDto.Statement,
                    Number            = z_OfficeDto.Number,
                    Caution           = z_OfficeDto.Caution,
                    AppearanceState   = z_OfficeDto.AppearanceState,
                    WarehousingTypeId = z_OfficeDto.WarehousingTypeId,
                };
                var result = await Task.Run(() => db.Entrepots.AsNoTracking().FirstOrDefaultAsync(p => p.Id > 0));

                OfficeRoom officeRoom = new OfficeRoom
                {
                    Id         = IdentityManager.NewId(),
                    OfficeId   = z_Office.Id,
                    EntrepotId = result.Id,
                    User_id    = userId,
                    RawNumber  = 0,
                };
                db.Offices.Add(officeRoom);
                db.Z_Office.Add(z_Office);
                if (await db.SaveChangesAsync() > 0)
                {
                    return(Json(new { code = 200, msg = "添加成功" }));
                }
                else
                {
                    return(Json(new { code = 400, msg = "添加失败" }));
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> RemoveOffice(Z_OfficeDto z_OfficeDto)
        {
            try
            {
                if (z_OfficeDto.del_Id != null)
                {
                    foreach (var item in z_OfficeDto.del_Id)
                    {
                        var result = new Z_Office {
                            Id = item
                        };
                        db.Entry(result).State = System.Data.Entity.EntityState.Unchanged;
                        result.del_or          = 1;
                        // var resul = new OfficeRoom { OfficeId = item };
                        var res = await db.Offices.SingleOrDefaultAsync(s => s.OfficeId == item);

                        if (res != null)
                        {
                            res.RawNumber         = 10;
                            res.RawOutNumber      = 0;
                            res.Warning_RawNumber = 0;
                        }
                    }
                    if (await db.SaveChangesAsync() > 0)
                    {
                        return(Json(new { code = 200, msg = "删除成功" }));
                    }
                    else
                    {
                        return(Json(new { code = 400, msg = "删除失败" }));
                    }
                }
                else
                {
                    return(Json(new { code = 201, msg = "请勿传递空数据" }));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 3
0
 public async Task <IHttpActionResult> EditOffice(Z_OfficeDto z_OfficeDto)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var type = new Models.Db.Aggregate.FinancialManagement.WarehouseManagements.Z_Office()
             {
                 Id = z_OfficeDto.Id
             };
             db.Entry(type).State = System.Data.Entity.EntityState.Unchanged;
             // Z_RawDto z_RawDto1 = new Z_RawDto();
             if (!string.IsNullOrWhiteSpace(z_OfficeDto.Name))
             {
                 type.Name = z_OfficeDto.Name;
             }
             if (z_OfficeDto.Companyid != null)
             {
                 type.CompanyId = z_OfficeDto.Companyid;
             }
             if (z_OfficeDto.Number != null)
             {
                 type.Number = z_OfficeDto.Number;
             }
             if (!string.IsNullOrWhiteSpace(z_OfficeDto.Encoding))
             {
                 type.Encoding = z_OfficeDto.Encoding;
             }
             if (z_OfficeDto.EntryPersonId != null)
             {
                 type.EntryPersonId = z_OfficeDto.EntryPersonId;
             }
             if (!string.IsNullOrWhiteSpace(z_OfficeDto.Desc))
             {
                 type.Desc = z_OfficeDto.Desc;
             }
             if (z_OfficeDto.Z_OfficeTypeid != null)
             {
                 type.Z_OfficeTypeid = z_OfficeDto.Z_OfficeTypeid;
             }
             if (!string.IsNullOrWhiteSpace(z_OfficeDto.EnglishName))
             {
                 type.EnglishName = z_OfficeDto.EnglishName;
             }
             if (!string.IsNullOrWhiteSpace(z_OfficeDto.Abbreviation))
             {
                 type.Abbreviation = z_OfficeDto.Abbreviation;
             }
             if (!string.IsNullOrWhiteSpace(z_OfficeDto.BeCommonlyCalled1))
             {
                 type.BeCommonlyCalled1 = z_OfficeDto.BeCommonlyCalled1;
             }
             if (!string.IsNullOrWhiteSpace(z_OfficeDto.BeCommonlyCalled2))
             {
                 type.BeCommonlyCalled2 = z_OfficeDto.BeCommonlyCalled2;
             }
             if (!string.IsNullOrWhiteSpace(z_OfficeDto.CASNumber))
             {
                 type.CASNumber = z_OfficeDto.CASNumber;
             }
             if (!string.IsNullOrWhiteSpace(z_OfficeDto.MolecularWeight))
             {
                 type.MolecularWeight = z_OfficeDto.MolecularWeight;
             }
             if (!string.IsNullOrWhiteSpace(z_OfficeDto.MolecularFormula))
             {
                 type.MolecularFormula = z_OfficeDto.MolecularFormula;
             }
             if (!string.IsNullOrWhiteSpace(z_OfficeDto.StructuralFormula))
             {
                 type.StructuralFormula = z_OfficeDto.StructuralFormula;
             }
             if (!string.IsNullOrWhiteSpace(z_OfficeDto.Density))
             {
                 type.Density = z_OfficeDto.Density;
             }
             if (!string.IsNullOrWhiteSpace(z_OfficeDto.Statement))
             {
                 type.Statement = z_OfficeDto.Statement;
             }
             if (!string.IsNullOrWhiteSpace(z_OfficeDto.Caution))
             {
                 type.Caution = z_OfficeDto.Caution;
             }
             if (!string.IsNullOrWhiteSpace(z_OfficeDto.AppearanceState))
             {
                 type.AppearanceState = z_OfficeDto.AppearanceState;
             }
             if (z_OfficeDto.WarehousingTypeId != null)
             {
                 type.WarehousingTypeId = z_OfficeDto.WarehousingTypeId;
             }
             if (await db.SaveChangesAsync() > 0)
             {
                 return(Json(new { code = 200, msg = "修改成功" }));
             }
             else
             {
                 return(Json(new { code = 200, msg = "修改失败" }));
             }
         }
         else
         {
             return(Json(new { code = 201, msg = "数据格式错误" }));
         }
     }
     catch (Exception)
     {
         throw;
     }
 }