예제 #1
0
        EntityCommandModel IGetModAddDelEntityService.AddEntity(EntityCommandModel entity)
        {
            var newEntity = new Data.Entity()
            {
                Name = entity.Name, EntityTypeId = entity.EntityTypeId, IsValid = true
            };

            var dbEntity = _unitWork.GetRepository <Data.Entity>().Get(x => x.Name == entity.Name);

            if (dbEntity != null)
            {
                // Duplicate entity found/ Entity exist
            }
            else
            {
                try
                {
                    _unitWork.GetRepository <Data.Entity>().Insert(newEntity);
                    _unitWork.Save();
                }
                catch
                {
                    // Database operation exception
                }
            }
            return(GetEntityById(newEntity.Id));
        }
예제 #2
0
        EntityCommandModel IGetModAddDelEntityService.ModifyEntity(EntityCommandModel entity)
        {
            Data.Entity currentEntity = null;
            try
            {
                currentEntity = _unitWork.GetRepository <Data.Entity>().Get(x => x.Id == entity.Id).SingleOrDefault();
            }
            catch (Exception ex)
            {
                if (ex is InvalidOperationException)
                {
                    throw new InvalidOperationException(); // Duplicate entity found
                }
                throw;
            }
            if (currentEntity == null)
            {
                // Entity not found
            }
            else
            {
                currentEntity.Name         = entity.Name;
                currentEntity.EntityTypeId = entity.EntityTypeId;

                try
                {
                    _unitWork.GetRepository <Data.Entity>().Update(currentEntity);
                    _unitWork.Save();
                }
                catch
                {
                    // Database operation exception
                }
            }
            return(GetEntityById(currentEntity.Id));
        }