Exemple #1
0
            /// <inheritdoc />
            public void Dispose()
            {
                if (Monitor.IsEntered(_itemLock))
                {
                    Monitor.Exit(_itemLock);
                }

                lock (OuterLock)
                {
                    RecordLocks.Remove(this);
                }
            }
Exemple #2
0
        public IActionResult Lock([FromBody] LockEntry newmodel)
        {
            if (ModelState.IsValid)
            {
                if (newmodel != null)
                {
                    /*
                     * var Entity = _mmmcontext.Entities.FirstOrDefault(x => x.Ent_ID == newmodel.IDFromWorkUnitsDBTable);
                     *
                     * if (Entity == null)
                     * {
                     *  return BadRequest("Profile not found with Id " + newmodel.IDFromWorkUnitsDBTable);
                     * }
                     */

                    // look for an existing lock
                    var existingLock = _context.RecordLocks
                                       .FirstOrDefault(x => (x.IDFromWorkUnitsDBTable == newmodel.IDFromWorkUnitsDBTable && x.WorkUnitTypeID == newmodel.WorkUnitTypeID));
                    //.FirstOrDefault(x => (x.IDFromWorkUnitsDBTable == newmodel.IDFromWorkUnitsDBTable && x.AppUserID == newmodel.AppUserID && x.WorkUnitTypeID == newmodel.WorkUnitTypeID));
                    if (existingLock != null)
                    {
                        return(BadRequest("Lock already exists for record"));
                    }

                    RecordLocks thisLock = new RecordLocks();
                    thisLock.AppUserID = newmodel.AppUserID;
                    thisLock.IDFromWorkUnitsDBTable   = newmodel.IDFromWorkUnitsDBTable;
                    thisLock.WorkUnitTypeID           = newmodel.WorkUnitTypeID;
                    thisLock.DateTimeItemWasLockedUTC = DateTime.UtcNow;

                    thisLock.CreatedBy      = newmodel.AppUserID.ToString();
                    thisLock.DateCreatedUTC = DateTime.UtcNow;
                    thisLock.UpdatedBy      = newmodel.AppUserID.ToString();
                    thisLock.LastUpdatedUTC = DateTime.UtcNow;

                    _context.RecordLocks.Add(thisLock);
                    ReturnData ret;
                    ret = _context.SaveData();

                    if (ret.Message == "Success")
                    {
                        return(Ok());
                    }

                    return(NotFound(ret));
                }
            }
            return(BadRequest());
        }
Exemple #3
0
            public RecordLock(Guid recordId)
            {
                _recordId = recordId;

                lock (OuterLock)
                {
                    var existingLock = RecordLocks.Find(l => l._recordId == recordId);
                    _itemLock = existingLock == null
                        ? new object()
                        : existingLock._itemLock;

                    RecordLocks.Add(this);
                }

                Monitor.Enter(_itemLock);
            }
Exemple #4
0
        public void RecordLocks()
        {
            IQueryable <RecordLocks> RecordLocksCollection = Enumerable.Empty <RecordLocks>().AsQueryable();
            RecordLocks ct = new RecordLocks {
                RecordLockID = 1, CreatedBy = "Test User 1"
            };

            Mock <IRecordLocksRepository> RecordLocksService = new Mock <IRecordLocksRepository>();

            object obj = new object();

            try
            {
                RecordLocksService.Setup(x => x.GetAll()).Returns(RecordLocksCollection);
                RecordLocksService.Setup(x => x.Get(It.IsAny <int>())).Returns(ct);
                RecordLocksService.Setup(x => x.Add(It.IsAny <RecordLocks>())).Returns(ct);
                RecordLocksService.Setup(x => x.Delete(It.IsAny <RecordLocks>())).Verifiable();
                RecordLocksService.Setup(x => x.Update(It.IsAny <RecordLocks>(), It.IsAny <object>())).Returns(ct);

                var RecordLocksObject = RecordLocksService.Object;
                var p1 = RecordLocksObject.GetAll();
                var p2 = RecordLocksObject.Get(1);
                var p3 = RecordLocksObject.Update(ct, obj);
                var p4 = RecordLocksObject.Add(ct);
                RecordLocksObject.Delete(ct);

                Assert.IsAssignableFrom <IQueryable <RecordLocks> >(p1);
                Assert.IsAssignableFrom <RecordLocks>(p2);
                Assert.Equal("Test User 1", p2.CreatedBy);
                Assert.Equal("Test User 1", p3.CreatedBy);

                RecordLocksService.VerifyAll();

                RecordLocksObject.Dispose();
            }
            finally
            {
                RecordLocksService = null;
            }
        }
Exemple #5
0
        public IActionResult Update([FromBody] RecordLocks editentry)
        {
            var result = _repository.Update(editentry, editentry.RecordLockID);

            return(Helper.CheckResult(result));
        }