Example #1
0
        public static EventHistoryDTO GetById(int id)
        {
            using (WarehouseContext db = new WarehouseContext())
            {
                var result = db.EventHistory.Where(x => x.Id == id).Select(
                    x => new EventHistoryDTO
                {
                    Id        = x.Id,
                    EventId   = x.EventId,
                    StartDate = x.StartDate,
                }).FirstOrDefault();

                return(result);
            }
        }
Example #2
0
 public IActionResult StockDelete([FromForm] Stock entity)
 {
     try
     {
         using (var db = new WarehouseContext())
         {
             db.Stocks.Remove(entity);
             int count = db.SaveChanges();
             return(Ok(count > 0));
         }
     }
     catch (Exception ex)
     {
         throw new Exception($"Hareket tipi silmede hata oluştu.Hata : {ex.GetaAllMessages()}");
     }
 }
Example #3
0
 public static List <EventDTO> GetAll()
 {
     using (WarehouseContext db = new WarehouseContext())
     {
         var result = db.Events.Where(x => x.IsDisabled == false).Select(
             x => new EventDTO
         {
             Id          = x.Id,
             Name        = x.Name,
             Description = x.Description,
             Executed    = x.Executed,
             UserId      = x.UserId,
         }).ToList();
         return(result);
     }
 }
Example #4
0
 public IActionResult Put([FromForm] Plant entity)
 {
     try
     {
         using (var db = new WarehouseContext())
         {
             db.Plants.Update(entity);
             int count = db.SaveChanges();
             return(Ok(count > 0));
         }
     }
     catch (Exception ex)
     {
         throw new Exception($"Update failed. Error : {ex.GetaAllMessages()}");
     }
 }
 public CResult <List <WebSpeedChangeBoxType> > GetSpeedChangeBoxList()
 {
     using (var db = new WarehouseContext()) {
         var speedChangeList = RepositoryIoc.GetSpeedChangeBoxTypeRepository(db).Get();
         var result          = new List <WebSpeedChangeBoxType>();
         foreach (var item in speedChangeList)
         {
             result.Add(new WebSpeedChangeBoxType()
             {
                 SpeedChangeBoxTypeID = item.SpeedChangeBoxTypeID,
                 SpeedChangeBoxName   = item.SpeedChangeBoxName,
             });
         }
         return(new CResult <List <WebSpeedChangeBoxType> >(result));
     }
 }
Example #6
0
 public IActionResult LocationTypeUpdate([FromForm] LocationType entity)
 {
     try
     {
         using (var db = new WarehouseContext())
         {
             db.LocationTypes.Update(entity);
             int count = db.SaveChanges();
             return(Ok(count > 0));
         }
     }
     catch (Exception ex)
     {
         throw new Exception($"Hareket tipi güncellemede hata oluştu.Hata : {ex.GetaAllMessages()}");
     }
 }
Example #7
0
 public static List <ReturnDTO> GetAll()
 {
     using (WarehouseContext db = new WarehouseContext())
     {
         var result = db.Returns.Where(x => x.IsDisabled == false).Select(
             x => new ReturnDTO
         {
             Id          = x.Id,
             Client      = x.Client,
             Date        = x.Date,
             Description = x.Description,
             Attachment  = x.Attachment,
         }).ToList();
         return(result);
     }
 }
Example #8
0
        public void Save(Manufacturer manufacturer)
        {
            using (var dbContext = new WarehouseContext())
            {
                if (manufacturer.Id.HasValue)
                {
                    dbContext.Entry(manufacturer).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    dbContext.Manufacturers.Add(manufacturer);
                }

                dbContext.SaveChanges();
            }
        }
Example #9
0
        public async Task Handle(ShoppingCartGotInactive message, IMessageHandlerContext context)
        {
            Console.WriteLine($"Ready to wipe cart {message.CartId}.", Color.Yellow);

            using (var db = WarehouseContext.Create())
            {
                var cartItems = await db.ShoppingCartItems
                                .Where(o => o.CartId == message.CartId)
                                .ToListAsync();

                db.ShoppingCartItems.RemoveRange(cartItems);
                await db.SaveChangesAsync();
            }

            Console.WriteLine($"Cart {message.CartId} wiped.", Color.Green);
        }
Example #10
0
 public static JObject LoadMetadata(string name)
 {
     using (var dbcontext = new WarehouseContext())
     {
         var data = dbcontext.Metadatas.FirstOrDefault(
             m => string.Equals(m.Name, name));
         if (data != null)
         {
             return(JObject.Parse(data.Content));
         }
         else
         {
             return(null);
         }
     }
 }
 public IActionResult Delete([FromForm] Location entity)
 {
     try
     {
         using (var db = new WarehouseContext())
         {
             db.Locations.Remove(entity);
             int count = db.SaveChanges();
             return(Ok(count > 0));
         }
     }
     catch (Exception ex)
     {
         throw new Exception($"Delete failed. Error : {ex.GetaAllMessages()}");
     }
 }
Example #12
0
 public static List <UserDTO> GetAll()
 {
     using (WarehouseContext db = new WarehouseContext())
     {
         var result = db.Users.Where(x => x.IsDisabled == false).Select(
             x => new UserDTO
         {
             FirstName   = x.FirstName,
             LastName    = x.LastName,
             Email       = x.Email,
             PhoneNumber = x.PhoneNumber,
             BirthDate   = x.BirthDate,
         }).ToList();
         return(result);
     }
 }
 public static List <ClientDTO> GetAll()
 {
     using (WarehouseContext db = new WarehouseContext())
     {
         var result = db.Clients.Where(x => x.IsDisabled == false).Select(
             x => new ClientDTO
         {
             Id          = x.Id,
             CompanyName = x.CompanyName,
             PostalCode  = x.PostalCode,
             Email       = x.Email,
             PhoneNumber = x.PhoneNumber,
             Address     = x.Address,
         }).ToList();
         return(result);
     }
 }
Example #14
0
 public static CResult <int> GetDepartmentIDByUserName(string userName)
 {
     if (string.IsNullOrWhiteSpace(userName))
     {
         return(new CResult <int>(-1, ErrorCode.ParameterError));
     }
     using (var db = new WarehouseContext()) {
         var user     = Membership.GetUser(userName);
         var id       = (int)user.ProviderUserKey;
         var userInfo = RepositoryIoc.GetUsersInfoRepository(db).FirstOrDefault(r => r.ID == id);
         if (userInfo == null)
         {
             return(new CResult <int>(-1, ErrorCode.UserInfoNoExist));
         }
         return(new CResult <int>(userInfo.DepartmentID.Value));
     }
 }
Example #15
0
        public static EventDTO GetById(int id)
        {
            using (WarehouseContext db = new WarehouseContext())
            {
                var result = db.Events.Where(x => x.Id == id).Select(
                    x => new EventDTO
                {
                    Id          = x.Id,
                    Name        = x.Name,
                    Description = x.Description,
                    Executed    = x.Executed,
                    UserId      = x.UserId,
                }).FirstOrDefault();

                return(result);
            }
        }
Example #16
0
        public static ReturnDTO GetById(int id)
        {
            using (WarehouseContext db = new WarehouseContext())
            {
                var result = db.Returns.Where(x => x.Id == id).Select(
                    x => new ReturnDTO
                {
                    Id          = x.Id,
                    Client      = x.Client,
                    Date        = x.Date,
                    Description = x.Description,
                    Attachment  = x.Attachment,
                }).FirstOrDefault();

                return(result);
            }
        }
        private void query_click(object sender, RoutedEventArgs e)
        {
            var filter = searchctl.BuildQueryString();

            if (string.IsNullOrEmpty(filter))
            {
                return;
            }

            using (var dbcontext = new WarehouseContext())
            {
                var querystr = "select * from Goods where " + filter;
                var data     = dbcontext.Database.SqlQuery <Goods>(querystr);
                goodsgrid.ItemsSource = null;
                goodsgrid.ItemsSource = data.ToList();
            }
        }
Example #18
0
 public IActionResult Post([FromForm] Plant entity)
 {
     try
     {
         using (var db = new WarehouseContext())
         {
             Helper.Instance.SetAudit(entity);
             db.Plants.Add(entity);
             int count = db.SaveChanges();
             return(Ok(count > 0));
         }
     }
     catch (Exception ex)
     {
         throw new Exception($"Insert failed. Error : {ex.GetaAllMessages()}");
     }
 }
 public static List <EquipmentDTO> GetAll()
 {
     using (WarehouseContext db = new WarehouseContext())
     {
         var result = db.Equipments.Where(x => x.IsDisabled == false).Select(
             x => new EquipmentDTO
         {
             Id      = x.Id,
             Type    = x.Type,
             Model   = x.Model,
             Mark    = x.Mark,
             AddDate = x.AddDate,
             Status  = x.Status,
         }).ToList();
         return(result);
     }
 }
Example #20
0
 public IActionResult LocationTypeInsert([FromForm] LocationType entity)
 {
     try
     {
         using (var db = new WarehouseContext())
         {
             Helper.Instance.SetAudit(entity);
             db.LocationTypes.Add(entity);
             int count = db.SaveChanges();
             return(Ok(count > 0));
         }
     }
     catch (Exception ex)
     {
         throw new Exception($"Hareket tipi girişinde hata oluştu.Hata : {ex.GetaAllMessages()}");
     }
 }
Example #21
0
        public static UserDTO GetById(int id)
        {
            using (WarehouseContext db = new WarehouseContext())
            {
                var result = db.Users.Where(x => x.Id == id).Select(
                    x => new UserDTO
                {
                    FirstName   = x.FirstName,
                    LastName    = x.LastName,
                    Email       = x.Email,
                    PhoneNumber = x.PhoneNumber,
                    BirthDate   = x.BirthDate,
                }).FirstOrDefault();

                return(result);
            }
        }
Example #22
0
        public CResult <List <WebUserInfo> > GetUserInfoListByDepartment(string userName)
        {
            using (var db = new WarehouseContext()) {
                MembershipUserCollection users = Membership.GetAllUsers();
                var userInfoRepository         = RepositoryIoc.GetUsersInfoRepository(db);
                var role            = Roles.GetRolesForUser(userName);
                var currentUser     = Membership.GetUser(userName);
                var currentUserInfo = userInfoRepository.FirstOrDefault(r => r.ID == (int)currentUser.ProviderUserKey);
                if (currentUserInfo == null)
                {
                    return(new CResult <List <WebUserInfo> >(new List <WebUserInfo>(), ErrorCode.UserInfoNoExist));
                }

                var currentDepartmentID = currentUserInfo.DepartmentID;
                var userInfos           = new List <WebUserInfo>();

                foreach (MembershipUser item in users)
                {
                    var userID = (int)item.ProviderUserKey;
                    var info   = userInfoRepository.FirstOrDefault(r => r.ID == userID && r.StateID == (int)RecordState.Show, CommonHelper.GetPropName <UsersInfo>(r => r.Department));
                    if (info == null)
                    {
                        continue;
                    }
                    var currentRoles = Roles.GetRolesForUser(item.UserName);
                    if ((role.Contains(PermissionEnum.系统管理员.ToString()) && currentRoles.Contains(PermissionEnum.班长.ToString())) ||
                        (info.DepartmentID == currentDepartmentID && !currentRoles.Contains(PermissionEnum.班长.ToString()) && !currentRoles.Contains(PermissionEnum.系统管理员.ToString())))
                    {
                        userInfos.Add(new WebUserInfo()
                        {
                            ID             = userID,
                            UserName       = (item.UserName),
                            Phone          = info.Phone,
                            DepartmentID   = info.DepartmentID,
                            DepartmentName = info.Department.DepartmentName,
                            Adress         = info.Adress,
                            IsMonitor      = currentRoles.Contains(PermissionEnum.班长.ToString()),
                            IsRemovalMan   = currentRoles.Contains(PermissionEnum.出库员.ToString()),
                            IsPutinMan     = currentRoles.Contains(PermissionEnum.入库员.ToString()),
                        });
                    }
                }
                return(new CResult <List <WebUserInfo> >(userInfos));
            }
        }
 public static List <EmployeeDTO> GetAll()
 {
     using (WarehouseContext db = new WarehouseContext())
     {
         var result = db.Employees.Where(x => x.IsDisabled == false).Select(
             x => new EmployeeDTO
         {
             Id             = x.Id,
             FirstName      = x.FirstName,
             LastName       = x.LastName,
             Email          = x.Email,
             PhoneNumber    = x.PhoneNumber,
             EmploymentDate = x.EmploymentDate,
             Workplace      = x.Workplace
         }).ToList();
         return(result);
     }
 }
        public static EquipmentDTO GetById(int id)
        {
            using (WarehouseContext db = new WarehouseContext())
            {
                var result = db.Equipments.Where(x => x.Id == id).Select(
                    x => new EquipmentDTO
                {
                    Id      = x.Id,
                    Type    = x.Type,
                    Model   = x.Model,
                    Mark    = x.Mark,
                    AddDate = x.AddDate,
                    Status  = x.Status,
                }).FirstOrDefault();

                return(result);
            }
        }
Example #25
0
 /// <summary>
 ///  Body for main view, check if userid session field is null.
 /// </summary>
 /// <returns></returns>
 public ActionResult Index()
 {
     //Check if user id is null
     if (Session["UserId"] == null)
     {
         var s = User.Identity.Name;
         using (var cont = new WarehouseContext())
         {
             //Getting user id by user name
             var firstOrDefault = cont.UserProfiles.FirstOrDefault(x => x.UserName == s);
             if (firstOrDefault != null)
             {
                 Session["UserId"] = firstOrDefault.UserId;
             }
         }
     }
     return(View());
 }
        public void SaveModel(ProductModel productModel)
        {
            using (var dbContext = new WarehouseContext())
            {
                if (productModel.Id.HasValue)
                {
                    dbContext.Entry(productModel).State = EntityState.Modified;
                    dbContext.Entry(productModel.Manufacturer).State = EntityState.Modified;
                }
                else
                {
                    dbContext.ProductModels.Add(productModel);
                    dbContext.Entry(productModel.Manufacturer).State = EntityState.Modified;
                }

                dbContext.SaveChanges();
            }
        }
Example #27
0
 public static List <OrderDTO> GetAll()
 {
     using (WarehouseContext db = new WarehouseContext())
     {
         var result = db.Orders.Where(x => x.IsDisabled == false).Select(
             x => new OrderDTO
         {
             Id               = x.Id,
             OrderItem        = x.OrderItem,
             ItemQuantity     = x.ItemQuantity,
             RecipientCompany = x.RecipientCompany,
             PostalCode       = x.PostalCode,
             CityTown         = x.CityTown,
             StreetAddress    = x.StreetAddress,
         }).ToList();
         return(result);
     }
 }
 public CResult <string> TwoDimensionCodeByBarCode(string barCode)
 {
     barCode = barCode.Trim();
     if (string.IsNullOrWhiteSpace(barCode))
     {
         return(new CResult <string>(string.Empty, ErrorCode.ParameterError));
     }
     using (var db = new WarehouseContext())
     {
         var warehouse = RepositoryIoc.GetWarehouseMRepository(db).FirstOrDefault(r => r.BarCode == barCode && r.StateID == (int)RecordState.Show, CommonHelper.GetPropName <WarehouseM>(r => r.TwoDimensioncode));
         if (warehouse == null)
         {
             return(new CResult <string>(string.Empty, ErrorCode.BarCodeNotExist));
         }
         var twoDimensioncode = warehouse.TwoDimensioncode;
         return(new CResult <string>(twoDimensioncode.TwoDimensionCodeNum));
     }
 }
        public static ClientDTO GetById(int id)
        {
            using (WarehouseContext db = new WarehouseContext())
            {
                var result = db.Clients.Where(x => x.Id == id).Select(
                    x => new ClientDTO
                {
                    Id          = x.Id,
                    CompanyName = x.CompanyName,
                    PostalCode  = x.PostalCode,
                    Email       = x.Email,
                    PhoneNumber = x.PhoneNumber,
                    Address     = x.Address,
                }).FirstOrDefault();

                return(result);
            }
        }
        public IActionResult List(int page = 1, int take = 0, int skip = 0, int pageSize = 0, string filter = "")
        {
            using (var db = new WarehouseContext())
            {
                int cnt = (pageSize == 0 ? db.Locations.Count() : pageSize);
                take = take == 0 ? cnt : take;

                IList <Location> res = (from l in db.Locations.Skip((page - 1) * cnt).Take(take)
                                        join cu in db.Users on l.createdUserId equals cu.UserId into c1
                                        from cu in c1.DefaultIfEmpty()

                                        join lu in db.Users on l.createdUserId equals lu.UserId into c2
                                        from lu in c2.DefaultIfEmpty()

                                        join lt in db.LocationTypes on l.locationTypeId equals lt.LocationTypeId into c3
                                        from lt in c3.DefaultIfEmpty()

                                        join locP in db.Locations on l.parentLocationId equals locP.LocationId into c4
                                        from locP in c4.DefaultIfEmpty()
                                        select new Location
                {
                    LocationId = l.LocationId,
                    code = l.code,
                    name = l.name,
                    createdDate = l.createdDate,
                    lastUpdatedDate = l.lastUpdatedDate,
                    createdUserId = l.createdUserId,
                    lastUpdatedUserId = l.lastUpdatedUserId,
                    createdUser = cu,
                    lastUpdatedUser = lu,
                    locationType = lt,
                    parentLocation = locP,
                    coords = l.coords,
                    outline = l.outline,
                    locationTypeId = l.locationTypeId,
                    parentLocationId = l.parentLocationId
                }).ToList();

                return(Ok(new GridData()
                {
                    rows = res, total = res.Count
                }));
            }
        }
 public WarehouseContextAdapter(WarehouseContext context)
 {
     _context = context;
 }
 public static void CleanDB()
 {
     using (var dbcontext = new WarehouseContext())
     {
     }
 }
        public static void AddSampleData()
        {
            using (var dbcontext = new WarehouseContext())
            {
                try
                {
                    var user1 = new User()
                    {
                        Name = "二娃",
                        Username = "******",
                        Password = "******",
                        IdentificationNumber = "310392198305114344",
                        PhoneNumber = "13543776409",
                        Company = "梁山",
                        Department = "库房管理部",
                        Memo = "(●'◡'●)"
                    };
                    dbcontext.Users.Add(user1);

                    var tg = new TagGroup()
                    {
                        Name = "功能"
                    };
                    dbcontext.TagGroups.Add(tg);

                    var tag1 = new Tag()
                    {
                        Name = "食品",
                        Group = tg
                    };
                    dbcontext.Tags.Add(tag1);

                    var tag2 = new Tag()
                    {
                        Name = "书籍",
                        Group = tg
                    };
                    dbcontext.Tags.Add(tag2);

                    var tag3 = new Tag()
                    {
                        Name = "酒水",
                        Group = tg
                    };
                    dbcontext.Tags.Add(tag3);

                    var product = new Product()
                    {
                        Name = "乐事薯片100g(清新黄瓜)",
                        ScanCode = "111"
                    };
                    dbcontext.Products.Add(product);

                    var good = new Goods()
                    {
                        GoodsCode = "111",
                        InboundDate = DateTime.Now,
                        Product = product,
                        State = GoodsState.Inbounding
                    };
                    dbcontext.Goods.Add(good);

                    dbcontext.SaveChanges();
                }
                catch
                {
                    // do nothing
                }
            }
            using (var dbcontext = new WarehouseContext())
            {
                var item = dbcontext.Goods.First();
            }
        }