예제 #1
0
        public async Task DeleteGroup(GroupIdInput[] input)
        {
            foreach (var id in input)
            {
                var find = await _context.UserGroups.FindAsync(id.GroupsId);

                find.Deleted = true;
                _context.Entry(find).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }
        }
예제 #2
0
        public async Task <bool> DeleteSite(long siteId)
        {
            var site = await _context.Sites.FindAsync(siteId);

            _context.Entry(site).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
            await _context.SaveChangesAsync();

            return(true);
        }
예제 #3
0
        public async Task <SimpleResult> AddSite(AddSiteViewModel input)
        {
            try
            {
                var site = await _context.Sites.FindAsync(input.Id);

                SimpleResult result;
                var          poco = new SitePoco
                {
                    Name      = input.Name,
                    Latitude  = input.LatLng.Lat,
                    Longitude = input.LatLng.Lng,
                    Address   = input.Address,
                    Abbr      = input.Abbr
                };
                if (site != null)
                {
                    site.Latitude              = input.LatLng.Lat;
                    site.Longitude             = input.LatLng.Lng;
                    site.Name                  = input.Name;
                    site.Abbr                  = input.Abbr;
                    site.Address               = input.Address;
                    _context.Entry(site).State = EntityState.Modified;
                    await _context.SaveChangesAsync();

                    result = new SimpleResult
                    {
                        IsSuccess = true
                    };
                }
                else
                {
                    result = await _domain.AddSite(poco);
                }
                return(result);
            }
            catch
            {
                return(new SimpleResult
                {
                    IsSuccess = false
                });
            }
        }
예제 #4
0
        public async Task <SimpleResult> SaveMaterialItems(TimesheetCodeInput input)
        {
            try
            {
                var timesheet = await _context.TimeSheets.Where(x => x.Code == input.Code).FirstOrDefaultAsync();

                foreach (var mat in input.Materials)
                {
                    var materials = await _context.Materials.Where(x => x.StockCode == mat.StockCode).FirstOrDefaultAsync();

                    if (materials != null)
                    {
                        var inventory = await _context.Inventories.Where(x => x.MaterialId == materials.Id).FirstOrDefaultAsync();

                        var matItemPoco = new MaterialItemPoco
                        {
                            BOM_No           = mat.BOM_No,
                            Deleted          = false,
                            TimeSheetId      = timesheet.Id,
                            Quantity         = Convert.ToDecimal(mat.Quantity),
                            StockDescription = mat.StockDescription,
                            StockCode        = mat.StockCode
                        };
                        inventory.Quantity = inventory.Quantity - matItemPoco.Quantity;
                        _context.Entry(inventory).State = EntityState.Modified;
                        _context.MaterialItems.Add(matItemPoco);
                    }
                    else
                    {
                        var non = new NonMaterialItemPoco
                        {
                            BOM_No      = mat.BOM_No,
                            Deleted     = false,
                            Description = mat.StockDescription,
                            Metric      = mat.Quantity.ToString(),
                            TimeSheetId = timesheet.Id
                        };
                        _context.NonMaterialItems.Add(non);
                    }
                }
                await _context.SaveChangesAsync();

                return(new SimpleResult
                {
                    IsSuccess = true
                });
            }
            catch
            {
                return(new SimpleResult
                {
                    IsSuccess = true
                });
            }
        }
예제 #5
0
        public async Task <SimpleResult> DeleteWarehouse(WarehousesIdInput input)
        {
            var poco = await GetWarehouse(input);

            poco.Deleted = true;
            _context.Entry(poco).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            await _context.SaveChangesAsync();

            return(new SimpleResult
            {
                IsSuccess = true
            });
        }
예제 #6
0
        public async Task UpdateUser(string userId)
        {
            var user = await _context.Users.FindAsync(userId);

            user.LastLoggedIn          = DateTime.Now;
            _context.Entry(user).State = EntityState.Modified;
            var apiRequests = await _context.LookupValues.Where(x => x.LookupValuesId == (long)LookupValueEnum.ApiRequests).LastOrDefaultAsync();

            if (apiRequests == null)
            {
                await _context.LookupValues.AddAsync(new LookupValue
                {
                    LookupValuesId = (long)LookupValueEnum.ApiRequests,
                    DataType       = DataType.Integer,
                    DataValue      = "1",
                    Updated        = DateTime.Now
                });
            }
            else
            {
                if (apiRequests.Updated.Date == DateTime.Today)
                {
                    var lastApi = Convert.ToInt32(apiRequests.DataValue);
                    lastApi = lastApi + 1;
                    var newLookup = new LookupValue
                    {
                        DataType       = DataType.Integer,
                        DataValue      = lastApi.ToString(),
                        LookupValuesId = (long)LookupValueEnum.ApiRequests,
                        Updated        = DateTime.Now
                    };
                    await _context.LookupValues.AddAsync(newLookup);
                }
                else
                {
                    await _context.LookupValues.AddAsync(new LookupValue
                    {
                        LookupValuesId = (long)LookupValueEnum.ApiRequests,
                        DataType       = DataType.Integer,
                        DataValue      = "1",
                        Updated        = DateTime.Now
                    });
                }
            }
            await _context.SaveChangesAsync();
        }