public ApiResult SaveRole(Role role) { var userId = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.Sid).Value; var result = new ApiResult(); if (role == null) { result.Message = MessageUtil.ParamInvalid; } else { if (role.Id == Guid.Empty) { role.Id = Guid.NewGuid(); var count = _context.Roles.Count(x => EF.Property <bool>(x, ConstData.ShadowPropName_IsDeleted) != true); role.RoleType = (int)Math.Pow(2.0, count * 1.0); _context.AttachAddEntity(role, userId); _context.Roles.Add(role); } else { _context.AttachUpdateEntity(role, userId); _context.Roles.Update(role); } if (_context.SaveChanges() > 0) { result.Data = role; result.ReturnCode = ApiReturnCode.Succeed; } } return(result); }
public ApiResult Post(Vendor vendor) { ApiResult result = new ApiResult { ReturnCode = ApiReturnCode.Error }; var userId = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.Sid).Value; if (vendor == null) { result.Message = MessageUtil.ParamInvalid; } else { if (vendor.Id == Guid.Empty) { vendor.Id = Guid.NewGuid(); _context.AttachAddEntity(vendor, userId); _context.Vendors.Add(vendor); } else { _context.AttachUpdateEntity(vendor, userId); _context.Vendors.Update(vendor); } if (_context.SaveChanges() > 0) { var dict = _context.Dictionaries.FirstOrDefault(x => x.Id == vendor.TypeID); result.Data = new { vendor.Id, vendor.Level, vendor.Address, vendor.ContactPhone, vendor.CustomerEval, vendor.Deadline, vendor.FactoryEval, vendor.ManagerName, vendor.ManagerPhone, vendor.Production, vendor.SerialNum, vendor.Style, vendor.TypeID, vendor.VendorName, vendor.Years, TypeName = dict.TypeName }; result.ReturnCode = ApiReturnCode.Succeed; } else { result.Message = "更新失败"; } } return(result); }
public ApiResult Post(Dictionary dictionary) { var result = new ApiResult { ReturnCode = ApiReturnCode.Error }; var userId = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.Sid).Value; if (dictionary.Id != Guid.Empty) { //update //_context. var item = _context.Dictionaries.FirstOrDefault(x => x.Id == dictionary.Id && EF.Property <bool>(x, ConstData.ShadowPropName_IsDeleted) != true); if (item == null) { result.Message = MessageUtil.ItemNotFound; } else { item.DicTypeID = dictionary.DicTypeID; item.TypeName = dictionary.TypeName; item.Description = dictionary.Description; _context.AttachUpdateEntity(item, userId); _context.SaveChanges(); result.Data = item; result.ReturnCode = ApiReturnCode.Succeed; } } else { dictionary.Id = Guid.NewGuid(); _context.AttachAddEntity(dictionary, userId); _context.Dictionaries.Add(dictionary); _context.SaveChanges(); result.Data = dictionary; result.ReturnCode = ApiReturnCode.Succeed; //_context.Entry<dictionary>().Property(ConstData.ShadowPropName_CreatedDate).CurrentValue = DateTime.Now; } return(result); }
public ApiResult Post(Mould mould) { ApiResult result = new ApiResult { ReturnCode = ApiReturnCode.Error }; var userId = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.Sid).Value; if (mould == null) { result.Message = MessageUtil.ParamInvalid; } else { var dictItem = _context.Dictionaries.FirstOrDefault(x => x.Id == mould.TypeID); if (mould.Id == Guid.Empty) { mould.Id = Guid.NewGuid(); _context.AttachAddEntity(mould, userId); _context.Moulds.Add(mould); } else { _context.AttachUpdateEntity(mould, userId); _context.Moulds.Update(mould); } #region update img if (mould.FrontImgID.HasValue && mould.FrontImgID.Value != Guid.Empty) { byte[] content; if (_cache.TryGetValue <byte[]>(mould.FrontImgID.Value, out content)) { if (_context.SystemImages.AsNoTracking().FirstOrDefault(x => x.Id == mould.FrontImgID.Value) != null) { _context.SystemImages.Update(new SystemImage { Id = mould.FrontImgID.Value, Content = content }); } else { _context.SystemImages.Add(new SystemImage { Id = mould.FrontImgID.Value, Content = content }); } _cache.Remove(mould.FrontImgID.Value); } } else { mould.FrontImgID = null; } if (mould.SideImgID.HasValue && mould.SideImgID.Value != Guid.Empty) { byte[] content; if (_cache.TryGetValue <byte[]>(mould.SideImgID.Value, out content)) { if (_context.SystemImages.AsNoTracking().FirstOrDefault(x => x.Id == mould.SideImgID.Value) != null) { _context.SystemImages.Update(new SystemImage { Id = mould.SideImgID.Value, Content = content }); } else { _context.SystemImages.Add(new SystemImage { Id = mould.SideImgID.Value, Content = content }); } //_cache.Remove(mould.FrontImgID.Value); } } else { mould.SideImgID = null; } if (mould.BackImgID.HasValue && mould.BackImgID.Value != Guid.Empty) { byte[] content; if (_cache.TryGetValue <byte[]>(mould.BackImgID.Value, out content)) { if (_context.SystemImages.AsNoTracking().FirstOrDefault(x => x.Id == mould.BackImgID.Value) != null) { _context.SystemImages.Update(new SystemImage { Id = mould.BackImgID.Value, Content = content }); } else { _context.SystemImages.Add(new SystemImage { Id = mould.BackImgID.Value, Content = content }); } _cache.Remove(mould.FrontImgID.Value); } } else { mould.BackImgID = null; } #endregion if (_context.SaveChanges() > 0) { var mouldItem = mould; result.Data = new { mouldItem.Id, mouldItem.Creator, mouldItem.BackImgID, mouldItem.FrontImgID, mouldItem.Height, mouldItem.RelateMaterial, mouldItem.SerialNum, mouldItem.SideImgID, mouldItem.Size, mouldItem.Spec, mouldItem.TypeID, mouldItem.Width, TypeName = dictItem == null ? "--" : dictItem.TypeName }; result.ReturnCode = ApiReturnCode.Succeed; } else { result.Message = "更新失败"; } } return(result); }
public ApiResult Post(Material material) { ApiResult result = new ApiResult { ReturnCode = ApiReturnCode.Error }; var userId = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.Sid).Value; if (material == null) { result.Message = MessageUtil.ParamInvalid; } else { var dictItem = _context.Dictionaries.FirstOrDefault(x => x.Id == material.TypeID); var vendorItem = _context.Vendors.FirstOrDefault(x => x.Id == material.VendorID); if (material.Id == Guid.Empty) { material.Id = Guid.NewGuid(); _context.AttachAddEntity(material, userId); _context.Materials.Add(material); } else { _context.AttachUpdateEntity(material, userId); _context.Materials.Update(material); } if (material.IconID.HasValue && material.IconID.Value != Guid.Empty) { byte[] content; if (_cache.TryGetValue <byte[]>(material.IconID.Value, out content)) { if (_context.SystemImages.AsNoTracking().FirstOrDefault(x => x.Id == material.IconID.Value) != null) { _context.SystemImages.Update(new SystemImage { Id = material.IconID.Value, Content = content }); } else { _context.SystemImages.Add(new SystemImage { Id = material.IconID.Value, Content = content }); } _cache.Remove(material.IconID.Value); } } else { material.IconID = null; } if (_context.SaveChanges() > 0) { var mateItem = material; result.Data = new { mateItem.Id, mateItem.Color, mateItem.ColorNum, mateItem.LeftCount, mateItem.MaterialQuality, mateItem.OpenSize, mateItem.Price, mateItem.SerialNum, mateItem.Spec, mateItem.TypeID, mateItem.VendorID, mateItem.Weight, mateItem.IconID, VendorNum = vendorItem == null ? "--" : vendorItem.SerialNum, TypeName = dictItem == null ? "--" : dictItem.TypeName }; result.ReturnCode = ApiReturnCode.Succeed; } else { result.Message = "更新失败"; } } return(result); }
public ApiResult Post(Production production) { ApiResult result = new ApiResult { ReturnCode = ApiReturnCode.Error }; var userId = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.Sid).Value; if (production == null) { result.Message = MessageUtil.ParamInvalid; } else { if (production.Id == Guid.Empty) { production.Id = Guid.NewGuid(); _context.AttachAddEntity(production, userId); _context.Productions.Add(production); } else { _context.AttachUpdateEntity(production, userId); _context.Productions.Update(production); } if (_context.SaveChanges() > 0) { result.Data = (from prodItem in _context.Productions.Where(x => EF.Property <bool>(x, ConstData.ShadowPropName_IsDeleted) != true && x.Id == production.Id) join matItem in _context.Dictionaries.Where(x => EF.Property <bool>(x, ConstData.ShadowPropName_IsDeleted) != true) on prodItem.MatTypeId equals matItem.Id join styleItem in _context.Dictionaries.Where(x => EF.Property <bool>(x, ConstData.ShadowPropName_IsDeleted) != true) on prodItem.StyleTypeId equals styleItem.Id join mouldItem in _context.Moulds.Where(x => EF.Property <bool>(x, ConstData.ShadowPropName_IsDeleted) != true) on prodItem.MouldId equals mouldItem.Id join mainVendor in _context.Vendors.Where(x => EF.Property <bool>(x, ConstData.ShadowPropName_IsDeleted) != true) on prodItem.MainVendorId equals mainVendor.Id join decorateVendor in _context.Vendors.Where(x => EF.Property <bool>(x, ConstData.ShadowPropName_IsDeleted) != true) on prodItem.DecorateVendorId equals decorateVendor.Id join sweatbandVendor in _context.Vendors.Where(x => EF.Property <bool>(x, ConstData.ShadowPropName_IsDeleted) != true) on prodItem.SweatbandVendorId equals sweatbandVendor.Id join customerItem in _context.Customers.Where(x => EF.Property <bool>(x, ConstData.ShadowPropName_IsDeleted) != true) on prodItem.CustomerId equals customerItem.Id select new { prodItem.Id, prodItem.SerialNum, prodItem.MatTypeId, MatTypeName = matItem.TypeName, prodItem.StyleTypeId, StyleTypeName = styleItem.TypeName, prodItem.Color, prodItem.Size, prodItem.MouldId, MouldNum = mouldItem.SerialNum, prodItem.ProcessCost, prodItem.MainVendorId, MainVendorNum = mainVendor.SerialNum, prodItem.MainCost, prodItem.DecorateVendorId, DecorateVendorNum = decorateVendor.SerialNum, prodItem.DecorateCost, prodItem.SweatbandVendorId, SweatbandVendorNum = sweatbandVendor.SerialNum, prodItem.SweatbandCost, prodItem.PacketCost, prodItem.TransportCost, prodItem.TotalCost, prodItem.CustomerId, CustomerNum = customerItem.SerialNum }).FirstOrDefault(); result.ReturnCode = ApiReturnCode.Succeed; } } return(result); }